Iteration statements

Iteration statements FOR, WHILE, REPEAT along with the quit statement EXIT

Keyword

Example

Description

FOR

FOR i:=0 TO 100 DO

    SUM:=SUM + a[i]

END_FOR;


FOR i:=0 TO 100 BY 10 DO

    IF a[i]>=100 THEN

        EXIT;

    END_IF;

END_FOR;

Defined number of loops with preset step width 1 or with user-defined step width

Do not use the value of the control variable (i in this example) after the loop is finished because different values have been assigned to it.

WHILE

i:=0;
WHILE i<=100 AND a[i]<100 DO
    i:=i+10;
END_WHILE;

Loop processing while checking the loop condition before the loop

REPEAT

i:=0;
REPEAT
    i:=i+10;
    UNTIL i>100 OR a[i]>=100
END_REPEAT;

Loop processing while checking the loop condition after the loop

EXIT

EXIT;

Non-conditional exiting of the loop

Modified on: 2019-01-26Feedback on this pagePanasonic hotline