20-sim webhelp > Language Reference > Statements > For To Do


For To Do

Navigation:  Language Reference > Statements >

For To Do

Previous pageReturn to chapter overviewNext page

Syntax

for variable = start to stop by step do

 equation;

 equation;

 ....

end;

Description

The for statement is designed to execute equation(s) a fixed number of times. It begins with the keyword for and an expression that specifies the number of times the equations within the for statement should be executed. The for statement ends with the keyword end. The default increment in a for statement is one (1), but you can use the keyword by to adjust the increment.

 

The equations within the for statement are always executed once. The for statement stops when the variable has exceeded the stop value.

Examples

variables

 real i,y[10];

equations

 for i = 1 to 2 do

         // executed 2 times: y[1] and y[2]

         y[i] = ran (1);

 end;

 for i = 2 to 4.1 by 2 do

         // executed 3 times: y[2], y[4] and y[6]

         y[i] = ran (1);

 end;

Limitations

1.The start, stop and step values must be scalars. The step value is optional. There are no limitations to the number of equations that can be used within the for statement.
2.Equations within an for statement have to be written in the correct order of execution, i.e. they are not rewritten into a causal form but executed sequentially.