146k views
2 votes
Which of the following statements is true about selection structures?

An else statement must be provided after the if statement.
The if statement can have no else statement corresponding
A break statement must be used in each case statement in a switch structure
There must be a default statement in the switch structure

User Wendy Adi
by
8.7k points

1 Answer

5 votes

Final answer:

The correct statement about selection structures is that an if statement can operate without an else statement. Other provided statements about switch structures either involve common practices, like the use of break and default statements, but are not absolute syntactical requirements.

Step-by-step explanation:

The statement amongst the options that is true about selection structures is: The if statement can have no else statement corresponding. In programming, an if statement can be used without an accompanying else statement. This allows the code to execute a block of code only if a certain condition is true and do nothing if the condition is false. Conversely, an else statement is optional and only used when there is a need to execute a different block of code if the if condition is false.

In the context of a switch structure, a break statement is typically used to terminate the current case and prevent the execution from falling through to subsequent cases. However, it is not mandated by the syntax alone; it's a logical requirement to ensure the correct control flow. Similarly, while it's a common practice to include a default case in a switch structure to handle any case not specifically addressed by the case statements, it's not a syntactical requirement. A default statement is recommended to ensure all possible cases are handled.

User Orolo
by
8.6k points