for()

Iterates over a range of values and executes a function for each iteration.

Programmers often refer to it as the 'for loop' because of the way in which it repeatedly loops until a particular condition is satisfied.

Hint: Use exec function to execute block.

Syntax

for(initialization, condition, increment, function)

Parameters

Parameter Type Description
initialization Any The initial expression, typically a variable assignment.
condition Any The condition that determines loop continuation.
increment Any The expression executed after each iteration.
function Any The function executed in each iteration.

Return Value

Examples

Print “Current count is X” for values 0 to 4

for(i=0, i<5, i=i+1, print("Current count is ", i));

Output:
Current count is 0
Current count is 1
Current count is 2
Current count is 3
Current count is 4

See also

for
loop
exec