17. Loop constructs

[<<<] [>>>]

ScriptBasic has a rich set of looping constructs. If you got used to a special construct you can have it in ScriptBasic. The looping constructs that ScriptBasic supports are:

While expression
 REM loop body
Wend

Repeat the loop body so long as long the expression is TRUE. Do the test before entering the loop.

Repeat
 REM loop body
Until expression

Repeat the loop body so long as long the expression is FALSE. The loop body is executed at least once and the test is performed after the execution of the loop body.

Do While expression
 REM loop body
Loop

This is just another form of the loop while/wend. Repeat the loop body so long as long the expression is TRUE and do the testing before the loop body execution.

Do Until expression
 REM loop body
Loop

Repeat the loop body so long as long the expression is FALSE. Do the testing before the loop body execution.

Do
 REM loop body
Loop While expression

Repeat the loop body so long as long the expression is TRUE. Do the testing after the loop body execution.

Do REM loop body Loop Until expression

Repeat the loop body so long as long the expression is FALSE. Do the testing after the loop body execution.

FOR variable=StartValue TO EndValue STEP StepValue
 REM loop body
NEXT

This loop loads the value of the StartValue into the variable. After the execution of the loop the variable is increased by the value of StepValue. The StepValue can also be negative, in which case the value of the variable will decrease. The loop is repeated so long as long the value reaches or steps over the EndValue. If the StartValue is already over the EndValue the loop is never executed.

The keyword STEP and the value after the keyword is optional. In this case the step value is one.


[<<<] [>>>]