3 while iteration, While iteration -15 – ElmoMC SimplIQ Software Manual User Manual

Page 44

Advertising
background image

SimplIQ

Software Manual

4BThe

SimplIQ

User Programming Language

MAN-SIMSW (Ver. 1.4)

5-15

ƒ

The iteration variable k must be declared as a variable. The iteration variable must
be scalar, not an array member. For example, the expression:
for k[10]=1:10

is illegal because k is an array.

Example:

Start user program or function.

float ra[20];

Float

array

declaration.

int ia[20];

Integer

array

declaration.

int k;

Variable

declaration.


for k=1:10

Start iteration loop.

ia[k]=100;

Update first 10 elements of integer array.

ra[k]=55.55;

Update first 10 elements of real array.


end

End of iteration loop.

5.7.3

While Iteration

Syntax:
while(expression

)


statement


end

The while keyword executes a statement repeatedly until expression becomes 0. The
expression can be logical and/or numerical. It may be within parentheses or without
parentheses.

Example:
OB[1]=0

Digital output 1 is OFF.

while(IB[1])

OB[1]=1

While digital input 1 is ON, digital output 1 is ON.

end

OB[1]=0;

Digital output 1 is OFF.



While (IB[2])

end

MO=1;

This command will be performed only after digital output 2 is OFF.

Advertising