For Loop

'for' is a looping attribute which is used to perform a set of instructions multiple times in a given range.

SRON provides 'for' attribute to work on for loop. To provide a start and end point to the loop, 'range' attribue is used.

Syntax of 'range':

range : (variable = start_point, end_point, steps)

Examples:

Correct Syntax:
    range : (Int i = 0, 10)
or
    range : (i = 0 , 10)

------------ 

Wrong Syntax:
    range : Int i = 0, 10
or
    range : (50)

By default, the steps are set as 1, so you don't need to specify it explicitly.

Sample Code to print 0 to 5 numbers.

OUTPUT :

0 1 2 3 4 5


Sample Code to print even number between 0 and 15.

OUTPUT :

2 4 6 8 10 12 14


Last updated