Challenge - 5 Problems
IF-THEN-ELSE Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediateOutput of a simple IF-THEN-ELSE in PLC
What will be the value of the output variable
Q after running this PLC code snippet?IF I = TRUE THEN Q := TRUE; ELSE Q := FALSE; END_IF;
PLC Programming
I := TRUE; IF I = TRUE THEN Q := TRUE; ELSE Q := FALSE; END_IF;
Attempts:
2 left
💡 Hint
Think about what happens when the input I is TRUE in the IF condition.
✗ Incorrect
Since I is TRUE, the IF condition is met, so Q is set to TRUE.
💻 Command Output
intermediateIF-THEN-ELSE with numeric comparison
Given the following PLC code, what is the value of
Output after execution?VAR Temp : INT := 25; Output : STRING; END_VAR IF Temp > 30 THEN Output := 'Hot'; ELSE Output := 'Cold'; END_IF;
PLC Programming
Temp := 25; IF Temp > 30 THEN Output := 'Hot'; ELSE Output := 'Cold'; END_IF;
Attempts:
2 left
💡 Hint
Check if 25 is greater than 30.
✗ Incorrect
Since 25 is not greater than 30, the ELSE branch runs, setting Output to 'Cold'.
📝 Syntax
advancedIdentify the syntax error in IF-THEN-ELSE
Which option contains a syntax error in the IF-THEN-ELSE statement in PLC Structured Text?
Attempts:
2 left
💡 Hint
Look for missing semicolons or missing END_IF.
✗ Incorrect
Option D is missing a semicolon after 'Y := TRUE', which causes a syntax error.
🔧 Debug
advancedWhy does this IF-THEN-ELSE not set the output?
Given this PLC code snippet, why does
Output remain FALSE after execution?VAR Input : BOOL := FALSE; Output : BOOL := FALSE; END_VAR IF Input THEN Output := TRUE; END_IF;
PLC Programming
Input := FALSE; Output := FALSE; IF Input THEN Output := TRUE; END_IF;
Attempts:
2 left
💡 Hint
Think about what happens when the IF condition is FALSE.
✗ Incorrect
The IF condition is FALSE, so the code inside the IF block does not run, leaving Output unchanged.
🚀 Application
expertDetermine the final value after nested IF-THEN-ELSE
What is the final value of
Result after running this nested IF-THEN-ELSE PLC code?VAR
A : INT := 5;
B : INT := 10;
Result : STRING;
END_VAR
IF A > B THEN
Result := 'A is greater';
ELSE
IF A = B THEN
Result := 'A equals B';
ELSE
Result := 'B is greater';
END_IF;
END_IF;PLC Programming
A := 5; B := 10; IF A > B THEN Result := 'A is greater'; ELSE IF A = B THEN Result := 'A equals B'; ELSE Result := 'B is greater'; END_IF; END_IF;
Attempts:
2 left
💡 Hint
Compare A and B values carefully through the nested conditions.
✗ Incorrect
Since A (5) is not greater than B (10), and A is not equal to B, the ELSE branch of the nested IF sets Result to 'B is greater'.
