For num1 TO, For num1 UNTIL

BlitzMax Forums/BlitzMax Beginners Area/For num1 TO, For num1 UNTIL

gimpy1(Posted 2006) [#1]
Hi All,

I'm trying to learn Bmax and came across a piece of code in a samle that came with the software I don't get.

For y=12 To 0 Step -1
For x=0 Until 8
If map[x,y]>0
If map[x,y+1]=0
map[x,y+1]=map[x,y]
map[x,y]=0
EndIf
EndIf
Next
Next

This is a common For,Next/Column,Row loop.
What is the signifigance between TO and UNTIL in the For statements?

For y=12 To 0 Step -1
For x=0 Until 8

The 'docs' don't give me a clue. I see For - TO, but not FOR - UNTIL.

Thanks ahead of time for any help you can offer.

Gimpy1


Chris C(Posted 2006) [#2]
its the same as doing to (8)-1

it loops until (not including) the target

most useful for

for x=0 until a.length
print a[x]
next


gimpy1(Posted 2006) [#3]
Thanks, Chris C.

So basically, TO and UNTIL do the same thing? The count actually stops at 1 before the target no matter which syntax is used, TO or UNTIL?


FlameDuck(Posted 2006) [#4]
No. To is inclusive, ie For Local a:int = 1 To 8; Print a;Next will print all numbers between 0 and 9, where as Until is exclusive, and For Local a:int = 0 Until 8; Print a;Next will only print the numbers between 0 and 8.


gimpy1(Posted 2006) [#5]
Now I got it!
Thanks FlameDuck!


GW(Posted 2006) [#6]

ie For Local a:int = 1 To 8; Print a;Next will print all numbers between 0 and 9



Eh!?
what Blitzmax are you using? Mine certainly doesn't do that.


WendellM(Posted 2006) [#7]

The 'docs' don't give me a clue. I see For - TO, but not FOR - UNTIL.

Neither "For" nor "Until" in the Modules/Blitz Runtime section of the help mention this use of "Until" (which would be handy to see in both entries). It is in the help, but tucked away in the Language/Program Flow section:

[img http://i15.photobucket.com/albums/a355/zoc/foruntil.gif]


xlsior(Posted 2006) [#8]
ie For Local a:int = 1 To 8; Print a;Next will print all numbers between 0 and 9

Eh!?
what Blitzmax are you using? Mine certainly doesn't do that.




Of course it does. It prints 1,2,3,4,5,6,7 and 8... which are all numbers between 0 and 9. He didn't say it would print 0 through 9...


CS_TBL(Posted 2006) [#9]
until @ for is a bit hacky as codefold IDEs prolly look for "until" as part of a repeat-loop to fold a repeat-scope..


JazzieB(Posted 2006) [#10]
Until will either be the first command on a line or the first command after a ';'. Any code folding routines shouldn't be looking for these sort of commands midway through any code lines/sections, they should only be looking at the first command and ignoring the rest.