Specifications
Section 9. Program Control Instructions
9-9
For I = 1 To 10
For J = 1 To 10
For K = 1 To 10
...
Next K
Next J
Next I
Note If you omit the variable in a Next statement, the value of Step
increment is added to the variable associated with the most recent
For statement. If a Next statement is encountered before its
corresponding For statement, an error occurs.
For...Next Statement Example
The example runs one For..Next loop inside another.
Dim I, J 'Declare variables.
For J = 5 To 1 Step -1 'Loop 5 times backwards.
For I = 1 To 12 'Loop 12 times.
. . . . 'Run some code.
Next I
. . . . 'Run some code.
Next J
. . . . 'Run some code.
This next example fills odd elements of X up to 40 * Y with odd numbers.
For I = 1 To 40 * Y Step 2
X( I ) = I
Next I
If ... Then ... Else Statement
Allows conditional execution, based on the evaluation of an expression.
Syntax 1
If condition Then thenstatements [Else elsestatementst]
Syntax 2
If condition1 Then
[statementblock-1]
[ElseIf condition2 Then
[statementblock-2] ]
[Else
[statementblock-n] ]
EndIf
Syntax 1 Description
The single-line form is often useful for short, simple conditional tests. Syntax
1 has these parts:
Part Description
If Begins the simple If...Then control structure.
condition An expression that evaluates true (nonzero) or false (0 and
Null).