Difference between 'To' and 'Until'
BlitzMax Forums/BlitzMax Programming/Difference between 'To' and 'Until'
| ||
Is there any? In the context of a For\Next loop, that is.For a = 0 To 10 Next For a = 0 Until 10 Next How are they different? Russell Russell |
| ||
The first loop will loop through 0,1,2,..8,9,10, the second 0,1,2,..8,9. For a = 1 Until x Is equivilant to For a = 1 To ( x - 1 ) Except that Until should be ever so slightly faster. |
| ||
thats cool because arrays start at 0. array[amount] you would want to loop 0 to (amount-1) |
| ||
It is primarily useful for looping through arrays and strings. Instead of having to remember to do this:For Local i=0 to (arrayVar.length-1) ... Next You can just do this instead: For Local i=0 Until arrayVar.length ... Next The difference isn't very significant, but I still find it quite handy. |
| ||
For/Until skips the last loop. Its main use is for iterating through zero-based data (eg. 5 items with values 0, 1, 2, 3, 4) without having to remember to use -1 on the end value -- you just go For a = 0 Until 5 to iterate through 5 zero-based items. |
| ||
Hmm... Not so sure if that is actually useful, but ok. :^/ Useful perhaps in some cases, but just weird enough to confuse the newbie (and also not explained in the manual...) But thanks for the reply! Russell |
| ||
I use Until probably more than I use To. It's second to none when you're working with arrays. |
| ||
I guess I've just gotten so used to doing it the 'old' way... Darn progress! ;) Russell |
| ||
I've been using BLtiz for years and I didn't even know you could do that. I wouldn't use it. I'm old frashined that way. Seems kind of silly for it to even be there. [edit] Pfft, I'm reading the BlitzMax forum... no wonder. :-) STILL SILLY TO ADD IT. [/edit] |