-
for next question
Hi As I'm programming microcontrollers (atmel avr) with the Bascom compiler, I've encounters the next issue:
Code:
Dim x as byte
For x = 0 to 20
print x
next
print x
end
as result I get the printing of "0" to "21"
seems confusing/unlogical to me since I asked to go to 20 and not to 21
Is this also case in other basics?
-
Re: for next question
I have never used the compiler you are using, but this is normal behaviour for many languages (including several/all versions of Basic). When a For loop ends, the loop variable is 1 higher than the "to" value you specified.
If you remove the second Print statement, you will not see this issue - you will only get 0 to 20 shown.