Challenge - 5 Problems
CASE Statement Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediateOutput of a simple CASE statement
What will be the output of the following PLC CASE statement when the input value is 3?
PLC Programming
VAR inputValue : INT := 3; outputValue : STRING; END_VAR CASE inputValue OF 1: outputValue := 'One'; 2: outputValue := 'Two'; 3: outputValue := 'Three'; ELSE outputValue := 'Other'; END_CASE // Output the value of outputValue
Attempts:
2 left
💡 Hint
Look at the case that matches the inputValue 3.
✗ Incorrect
The CASE statement matches the inputValue 3 and assigns 'Three' to outputValue.
💻 Command Output
intermediateCASE statement with ELSE branch
What will be the output of the CASE statement if inputValue is 5?
PLC Programming
VAR inputValue : INT := 5; outputValue : STRING; END_VAR CASE inputValue OF 1: outputValue := 'One'; 2: outputValue := 'Two'; 3: outputValue := 'Three'; ELSE outputValue := 'Other'; END_CASE // Output the value of outputValue
Attempts:
2 left
💡 Hint
Check what happens when no case matches and ELSE is present.
✗ Incorrect
Since 5 does not match any case, the ELSE branch assigns 'Other'.
📝 Syntax
advancedIdentify the syntax error in CASE statement
Which option contains a syntax error in the CASE statement?
Attempts:
2 left
💡 Hint
Look for missing colon after case value.
✗ Incorrect
Option D is missing a colon after '1', causing a syntax error.
🚀 Application
advancedUsing CASE statement for multiple outputs
Given the following CASE statement, what will be the value of outputValue after execution if inputValue is 4?
PLC Programming
VAR inputValue : INT := 4; outputValue : STRING; END_VAR CASE inputValue OF 1, 2: outputValue := 'Low'; 3, 4: outputValue := 'Medium'; 5: outputValue := 'High'; ELSE outputValue := 'Unknown'; END_CASE // Output the value of outputValue
Attempts:
2 left
💡 Hint
Check which case group includes 4.
✗ Incorrect
The CASE statement groups 3 and 4 together, so inputValue 4 sets outputValue to 'Medium'.
🧠 Conceptual
expertBehavior of CASE statement without ELSE branch
What happens if a CASE statement in PLC code does not include an ELSE branch and the input value does not match any case?
Attempts:
2 left
💡 Hint
Think about what happens when no case matches and no ELSE is provided.
✗ Incorrect
Without an ELSE branch, if no case matches, the CASE statement does nothing, so the output variable remains unchanged.
