0
0
C Sharp (C#)programming~5 mins

If statement execution flow in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of an if statement in C#?
An if statement checks a condition and runs a block of code only if that condition is true.
Click to reveal answer
beginner
What happens when the condition in an if statement is false?
The code inside the if block is skipped, and the program continues with the next statement after the if block.
Click to reveal answer
beginner
Explain the flow of an if-else statement.
If the if condition is true, its block runs. If false, the else block runs instead.
Click to reveal answer
intermediate
What is the role of else if in C#?
else if lets you check multiple conditions one after another. The first true condition runs its block, and the rest are skipped.
Click to reveal answer
intermediate
How does the program decide which block to execute in an if-else if-else chain?
It checks each condition from top to bottom. The first condition that is true runs its block, and the rest are ignored. If none are true, the else block runs.
Click to reveal answer
What happens if the if condition is false and there is no else block?
AThe program skips the <code>if</code> block and continues after it.
BThe program runs an error.
CThe program stops running.
DThe program runs the <code>if</code> block anyway.
In an if-else if-else chain, how many blocks can run?
AAll blocks run.
BOnly the <code>else</code> block runs.
COnly the first true condition's block runs.
DNone run.
Which keyword allows checking multiple conditions in sequence?
Aelse
Belse if
Cswitch
Dfor
What is the correct syntax to start an if statement in C#?
Aif (condition) { }
Bif condition { }
Cif: condition { }
Dif [condition] { }
What does the program do after finishing an if block?
AIt repeats the <code>if</code> block.
BIt stops running.
CIt jumps to the start of the program.
DIt continues with the next statement after the <code>if</code> block.
Describe how an if-else if-else statement controls the flow of a program.
Think about how the program chooses which code to run based on conditions.
You got /4 concepts.
    Explain what happens when an if condition is false and there is no else block.
    Consider what the program does when the condition is not met and no alternative is given.
    You got /3 concepts.