BeSly Software Solutions About yab About us Admin


for -- starts a for-loop

for a=1 to 100 step 2 
next a 

The for-loop lets its numerical variable (a in the synopsis) assume all valueswithin the given range. The optional step-clause may specify a value (default: 1) by which the variable will be incremented (or decremented, if step is negative).

Any for-statement can be replaced by a set of ifs and gotos; as you may infer from the example below this is normally not feasable. However if you want to know in detail how the for-statement works, you should study this example, which presents a for-statement and an exactly equivilant series of ifs and gotos.

for a=1 to 10 step 2
	print a
next a

label check 
if (a>10) goto done 
print a 
goto check 
label done 

This example simply prints the numbers 1, 3, 5, 7 and 9. It does this twice: 
First with a simple for-statment and then with ifs and gotos.

Related: step, next