Question Detail

COS 102 If staments Objective Question

Question

What is the primary purpose of the else clause in an if-else statement?
Options
A To execute code if the initial <code>if</code> condition is True.
B To define an alternative action if the <code>if</code> condition is False.
Correct Answer
C To create multiple conditions that must all be True.
D To assign a new value to a variable.
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 8, 'The 'Else' Clause (The Backup)', explains that 'What if the condition is False? We can provide a backup plan using else.' It acts as a fallback or alternative if the initial condition is not met.

Hint

Think of 'else' as a 'backup plan' when the main condition isn't met.

Question Info