Page 1 of 1

Wish: Loop (x)

Posted: Sat Jan 28, 2006 11:38 am
by Trond
Like:

Code: Select all

Loop 10
  AddElement(LinkedList())
EndLoop
Should add 10 (or 11?) elements to the linked list witohut having to use more variables.

Posted: Sat Jan 28, 2006 1:10 pm
by blueznl
i see little win over

Code: Select all

for n = 1 to 10
  addelement(...)
next n

Posted: Sat Jan 28, 2006 1:20 pm
by Trond
Then you need another variable.

Posted: Sat Jan 28, 2006 1:25 pm
by Dare2

Code: Select all

Repeat
  AddElement(LinkedList())
Until CountList(LinkedList()) = 10
:)

Sorry (not really), just being hair-splitty.

I like/support the Loop n .. EndLoop idea. Maybe version 4.01:)

Posted: Sat Jan 28, 2006 1:54 pm
by Trond
Dare2 wrote:

Code: Select all

Repeat
  AddElement(LinkedList())
Until CountList(LinkedList()) = 10
:)

Sorry (not really), just being hair-splitty.

I like/support the Loop n .. EndLoop idea. Maybe version 4.01:)
I don't know how many elements which is currently in the list, but I found another way to do it without using an extra variable.

Posted: Sat Jan 28, 2006 11:32 pm
by kenmo
But... for the program to keep track of how many times its looped, there's gonna be an internal variable anyway... so the only difference would be the way you type it. (ie zero benefit in the end)

Posted: Sun Jan 29, 2006 9:24 am
by josku_x
If I understand right, yes, you need a caounter variable, like:

Code: Select all

Repeat
 AddElement(LinkedList())
 Counter+1
Until Counter=10

Posted: Sun Jan 29, 2006 11:25 am
by Trond
kenmo wrote:But... for the program to keep track of how many times its looped, there's gonna be an internal variable anyway... so the only difference would be the way you type it. (ie zero benefit in the end)
It would be easy to use a register for this, thus giving a speed boost. Also, if you don't care about the way you type it, you might as well program only in assembly.

Posted: Sun Jan 29, 2006 12:40 pm
by PB
> I found another way to do it without using an extra variable

Which was? :)

Posted: Sun Jan 29, 2006 12:58 pm
by Trond

Code: Select all

      Repeat 
        AddElement(Memory())
      Until CountList(Neurons()) = CountList(Memory())
Image

Posted: Sun Jan 29, 2006 1:04 pm
by Dare2
:D

In other words, 2.

Posted: Sun Jan 29, 2006 1:18 pm
by Trond
Two what?

And anyways it would still be faster speed-wise with this (optimized with the counter in a register):

Code: Select all

Loop CountList(Neurons()) - CountList(Memory())
  AddElement(Memory()) 
EndLoop

Posted: Sun Jan 29, 2006 2:35 pm
by Dare2
2 Lists. Or neurons :) Okay if you had the extra list to start with. Bit more than a variable in cost, otherwise.

I like the simplicity of the Loop n syntax.

However I can't see any real gain (eg, extra variable). Surely a register would need to be preserved (stacked or stored in memory) to be safe, there is no knowing what the code in between Loop and EndLoop does.

BTW, is there a point where this sort of thing self-defeating (not necessarily just this)? For eg, using 100 bytes of code to save 4 (or 8, or whatever) bytes of storage. Or of investing 6 months of messing around with code to improve execution speed by 1 clock per hour?

Posted: Mon Jan 30, 2006 5:34 pm
by hardfalcon

Code: Select all

Loop 10
  AddElement(LinkedList())
EndLoop
That could AFAIK be done with ASM (unfortunately I don't REALLY know how to code in ASM). But there was, if I remember right, an Op-Code which keeps on jumping to an offset which you can specify until a certain register reaches a certain value. But I'm just an ASM-N0000B..... :oops: