Challenge - 5 Problems
Loop Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediateOutput of a FOR loop incrementing a counter
What is the value of the counter variable after this FOR loop runs in a PLC structured text program?
PLC Programming
VAR counter : INT := 0; i : INT; END_VAR FOR i := 1 TO 5 DO counter := counter + 2; END_FOR
Attempts:
2 left
💡 Hint
Think about how many times the loop runs and how much the counter increases each time.
✗ Incorrect
The FOR loop runs from 1 to 5, so 5 times. Each time, counter increases by 2. So 2 * 5 = 10.
💻 Command Output
intermediateWHILE loop execution count
How many times does the WHILE loop execute in this PLC structured text code?
PLC Programming
VAR count : INT := 0; x : INT := 3; END_VAR WHILE x < 7 DO count := count + 1; x := x + 2; END_WHILE
Attempts:
2 left
💡 Hint
Check how x changes each loop and when the condition becomes false.
✗ Incorrect
x starts at 3, increments by 2 each loop: 3, 5, 7. Loop runs while x < 7, so runs twice (x=3 and x=5).
📝 Syntax
advancedIdentify the syntax error in this FOR loop
Which option shows the correct syntax for a FOR loop in PLC structured text?
PLC Programming
FOR i := 1 TO 5 counter := counter + i; END_FOR
Attempts:
2 left
💡 Hint
Look for the required keyword after the FOR statement.
✗ Incorrect
In PLC structured text, FOR loops require 'DO' after the range declaration.
🔧 Debug
advancedWhy does this WHILE loop never end?
What is the reason this WHILE loop runs forever in PLC structured text?
PLC Programming
VAR x : INT := 0; END_VAR WHILE x < 5 DO x := x - 1; END_WHILE
Attempts:
2 left
💡 Hint
Think about how the variable changes and the loop condition.
✗ Incorrect
x starts at 0 and decreases by 1 each loop, so it stays less than 5 forever, never ending the loop.
🚀 Application
expertCalculate sum of even numbers using FOR loop
Which code correctly calculates the sum of even numbers from 2 to 10 inclusive in PLC structured text?
Attempts:
2 left
💡 Hint
Check which code sums only even numbers correctly.
✗ Incorrect
Option A loops from 1 to 10, adds i only if i is even (i MOD 2 = 0). This sums 2,4,6,8,10 correctly.
