-
-
Notifications
You must be signed in to change notification settings - Fork 2
For
The For(
token is used to repeat code a certain amount of times, while using a variable as a counter. It must be paired with an End
and has two different syntax forms, the second with a minor difference. The first one is For(VAR,START,END)
, with VAR
being the variable to use in the loop, START
being an expression stating the starting value of VAR
, and END
being an expression stating the ending value of VAR
. A For(
loop will first store the starting entry in VAR
and check if VAR
is now greater than END
. If VAR
is not greater than END
, the code in it's loop will be run. At the end, VAR
is incremented by 1, and the greater than check is done again. The loop will continue repeating until VAR
is greater than END
.
The second syntax form of For(
is For(VAR,START,END,INCREMENT)
. VAR
, START
, and END
are the same as in the first syntax form, and the INCREMENT
is an expression that will be added to VAR
at the end of each loop. That allows you to increment the counter by more than just one at a time. If you use a negative constant (no vars, as this is done at compile time) for INCREMENT
, the loop will continue until VAR
is END
. Example:
For(A,1,20
ClrHome
Disp A
Pause 200
End
The example will first display 1 to the screen, then pause for 200 milliseconds (⅕ of a second), and continue through the loop, displaying the value of A
as it increments. After it displays 20 to the screen, the program exists as the loop finishes and there is no more code after the loop.
ICE Compiler | Peter Tillema
- Introduction
- Building your first program
- Math and numbers
- Variables
- Standard system commands
- Program flow control
- Pointers
- Graphics
- Sprites
- Tilemaps
- Useful routines