FC0-U61 · Question #27
A program needs to choose apples, oranges, or bananas based on an input. Which of the following programming constructs is BEST to use?
The correct answer is B. If. An if statement is a programming construct that is best to use when a program needs to choose among different options based on an input. An if statement evaluates a condition and executes a block of code if the condition is true. An if statement can also have an else clause that
Question
A program needs to choose apples, oranges, or bananas based on an input. Which of the following programming constructs is BEST to use?
Exhibit
Options
- AVariable
- BIf
- CDatatype
- DComment
How the community answered
(34 responses)- B91% (31)
- C6% (2)
- D3% (1)
Explanation
An if statement is a programming construct that is best to use when a program needs to choose among different options based on an input. An if statement evaluates a condition and executes a block of code if the condition is true. An if statement can also have an else clause that executes a different block of code if the condition is false. An if statement can also have multiple else-if clauses that check for additional conditions. For example, a program that chooses apples, oranges, or bananas based on an input could use an if statement like this: A variable is a named memory location that can store a value, not a programming construct that can choose among options. A datatype is a classification of data that defines the possible values and operations for that data, not a programming construct that can choose among options. A comment is a remark or explanation in the source code that is ignored by the compiler or interpreter, not a programming construct that can choose among options.
Topics
Community Discussion
No community discussion yet for this question.
