A Brief Introduction to TwinCAT PLC Control Let us assume that the default setting for Var1 is the value 1. Then it will have the value 32 after the FOR loop. The can not be the limit of the counter .E.g. if the variable counter is of type SINT, and if is 127, you get an endless loop. 2.2.3.2 REPEAT loop The REPEAT loop is different from the WHILE loop because the break-off condition is checked only after the loop has been executed. This means that the loop will run through at least once, regardless of the wording of the break-off condition. Syntax: REPEAT UNTIL END_REPEAT; The are carried out until the returns TRUE.
If is produced already at the first TRUE evaluation, then are executed only once. If never assumes the value TRUE, then the are repeated endlessly which causes a relative time delay. The programmer must make sure that no endless loop is caused. He does this by changing the condition in the instruction part of the loop, for example by counting up or down one counter. Example: REPEAT Var1 := Var1*2; Counter := Counter-1; UNTIL Counter=0 END_REPEAT 2.2.3.3 WHILE loop The WHILE loop can be used like the FOR loop with the difference that the break-off condition can be any Boolean expression. This means you indicate a condition which, when it is fulfilled, the loop will be executed. Syntax:
WHILE DO END_WHILE; The are repeatedly executed as long as the returns TRUE. If the is already FALSE at the first evaluation, then the are never executed. If never assumes the value FALSE, then the are repeated endlessly which causes a relative time delay. The programmer must make sure that no endless loop is caused. He does this by changing the condition in the instruction part of the loop, for example, by counting up or down one counter. Example: WHILE counter 0 DO Var1 := Var1*2; TX1200 21 Version: 1.3