for Statement Numeric Iteration

Action

Uses numeric iteration to control the number of times a statement executes.

Syntax

for loop-var = start-expr to end-expr [step step-expr] statement
Variable Description
loop-var A loop variable to hold the current value of the for loop.
start-expr A number which specifies the starting value of loop-var.
end-expr A number which specifies the end value of loop-var.
step-expr

Optional for incrementing loop-var by a value other than 1. Specify a positive number to increment, a negative number to decrement.

Note: You must specify an explicit step-expr to decrement a loop. For example, to decrement a loop by 1, specify step -1. If you fail to do this, the for statement skips the loop but does not generate an error.
statement Code to be executed a specified number of times until loop-var is outside the range start-expr to end-expr; either a single statement or a series of statements.

Note

If you set the Step value in a "for" loop as a real, Silk Test Classic will use reals as the increments if the loop control counter is also declared as a real.

Example

[-] testcase ForExample()
	[ ] INTEGER i = 0
	[-] for i = 2 to 9 step 2
		[ ] Print(i)
	[ ] // This script prints:
	[ ] // 2
	[ ] // 4
	[ ] // 6
	[ ] // 8