Conditional statements in programming control the flow based on specific conditions. Mastering if, else, and else if statements, the Ternary Operator, and switch case statements will enhance decision-making capabilities in coding. Below are 30 multiple-choice questions covering these essential topics.
if statement?
else statement.switch statement to work.if-else statement?
if (condition) {code}if {code}if (condition) {code} else {code}if else {code}else clause in an if-else statement?
if condition is true.if condition is false.if block.switchelseelse iftry-catchif statement?
if (x > 10) { if (y > 5) { // code } }if (x > 10 && y > 5) { // code }if (x > 10) { // code } else if (y > 5) { // code }if (x > 10 || y > 5) { // code }int x = 5; if (x > 10) { x += 1; } else { x -= 1; }
else if ladder?
if statement.else if statement can:
if statement.if statement.if-else statement block in most programming languages?
endclose};if (x > 0 && y < 5), which logical operator is used?
switch statementwhile loopif-else statementfor loopcondition ? if_true : if_falsecondition : if_true ? if_falsecondition ? if_false : if_trueif_true : condition ? if_falsex = (a > b) ? a : b;?
if (a > b) { x = a; } else { x = b; }if (a < b) { x = a; } else { x = b; }x = a + b;x = (a > b);y have after the following code?int x = 10; int y = (x > 5) ? 1 : 0;
result = (age >= 18) ? "Adult" : "Minor";, what does "Adult" represent?
result = (x > 0) : x : -x;result ? (x > 0) : x : -xresult = (x > 0) ? x : -x;result = x : x : -xif-else statementsswitch statementsif-elseif-else structuresx = (y > 10) ? y : 10;?
if (y > 10) { x = 10; } else { x = y; }if (y < 10) { x = 10; } else { x = y; }x = (y < 10) ? 10 : y;x = 10;: symbol do?
switch statement use?
booleanfloatstringarrayswitch statement?
breakendcasecontinuedefault case executed in a switch statement?
switch syntax?
switch (x) { case 1; //code break; }switch x { case 1; //code break }switch (x) { case 1: //code break; }switch x ( case 1; //code break; )break statement in a switch case?
switch block.switch statement is ideal for:
default case in a switch statement?
switch statement cannot handle:
int data typesfloat valuesswitch statement, how do you execute the same code for multiple cases?
switch blockbreak in multiple casesswitch for each caseswitch statement?
| Qno | Answer |
|---|---|
| 1 | B. It executes code only if a specified condition is true |
| 2 | C. if (condition) {code} else {code} |
| 3 | B. To execute code when the if condition is false |
| 4 | C. else if |
| 5 | A. if (x > 10) { if (y > 5) { // code } } |
| 6 | C. x = 4 |
| 7 | C. All conditions are evaluated |
| 8 | A. Only follow an if statement |
| 9 | C. } |
| 10 | B. && |
| 11 | C. if-else statement |
| 12 | A. condition ? if_true : if_false |
| 13 | A. if (a > b) { x = a; } else { x = b; } |
| 14 | C. 1 |
| 15 | B. The true expression |
| 16 | C. result = (x > 0) ? x : -x; |
| 17 | C. With nested ternary operators |
| 18 | A. Simplifies code for simple conditions |
| 19 | B. if (y < 10) { x = 10; } else { x = y; } |
| 20 | C. Separates true and false expressions |
| 21 | C. string |
| 22 | A. break |
| 23 | C. If none of the cases match |
| 24 | C. switch (x) { case 1: //code break; } |
| 25 | C. It executes the next case’s code |
| 26 | A. Simple, exact-match conditions |
| 27 | C. It runs if no other case matches |
| 28 | C. float values |
| 29 | B. Omit break in multiple cases |
| 30 | C. For complex conditionals |