selection Flashcards
(11 cards)
What does the conditional (age <= 5) ? “Infant” : (age <= 12) ? “Child” : … represent?
It uses the ternary operator to assign an age group based on the age input.
Rewrite a nested ternary operator using if…else if…else.
if (age <= 5) AgeGroup = “Infant”;
else if (age <= 12) AgeGroup = “Child”;
…
What is the purpose of switch statements in selection?
To simplify multiple conditional branches comparing a single variable.
What operator is used for combining conditions?
Logical operators like &&, ||.
What is the output of: (x > 10) && (x < 75) if x = 20?
true
When should you use else if instead of separate if blocks?
When conditions are mutually exclusive.
Which statement assigns “PASS” if average is 55?
if (avg < 60) grade = “PASS”;
What is a nested if statement?
An if statement inside another if.
How would you write a simple grade classifier using if?
if (avg < 50) grade = “FAIL”;
else if (avg < 60) grade = “PASS”;
Can switch be used with strings in C#?
Yes, C# supports switch on strings.