Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a FOR loop that counts from 1 to 5.
PLC Programming
FOR i := 1 TO [1] DO // loop body END_FOR;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 6 as the upper limit causes the loop to run one extra time.
Using 0 as the upper limit makes the loop not run at all.
✗ Incorrect
The FOR loop counts from 1 to 5, so the upper limit must be 5.
2fill in blank
mediumComplete the code to create a WHILE loop that runs while the variable count is less than 10.
PLC Programming
count := 0; WHILE count [1] 10 DO count := count + 1; END_WHILE;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' causes the loop to never run.
Using '<=' makes the loop run one extra time.
✗ Incorrect
The loop should run while count is less than 10, so the operator is '<'.
3fill in blank
hardFix the error in the FOR loop that counts down from 5 to 1.
PLC Programming
FOR i := 5 TO [1] BY -1 DO // loop body END_FOR;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 causes the loop to run one extra time.
Using 6 causes the loop to not run correctly.
✗ Incorrect
To count down from 5 to 1, the loop must end at 1 with a step of -1.
4fill in blank
hardFill both blanks to create a FOR loop that sums numbers from 1 to 10.
PLC Programming
sum := 0; FOR i := [1] TO [2] DO sum := sum + i; END_FOR;
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 0 includes an extra number.
Ending at 5 sums only half the range.
✗ Incorrect
The loop starts at 1 and ends at 10 to sum all numbers in that range.
5fill in blank
hardFill all three blanks to create a WHILE loop that counts down from 10 to 1.
PLC Programming
count := [1]; WHILE count [2] 0 DO // do something count := count [3] 1; END_WHILE;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' makes the loop never run.
Using '+' increases count and causes an infinite loop.
✗ Incorrect
The loop starts at 10, runs while count is greater than 0, and decreases count by 1 each time.
