Recall & Review
beginner
What is the purpose of an if–else statement in Go?
An if–else statement lets the program choose between two paths based on a condition. If the condition is true, it runs one block of code; if false, it runs another.
Click to reveal answer
beginner
How do you write a simple if statement in Go?
Use the keyword
if followed by a condition, then a block of code in curly braces. Example:<br>if x > 10 {
fmt.Println("x is greater than 10")
}Click to reveal answer
beginner
What is the syntax for an if–else statement in Go?
You write
if with a condition and code block, then else with another code block. Example:<br>if x > 10 {
fmt.Println("big")
} else {
fmt.Println("small")
}Click to reveal answer
intermediate
Can you use multiple conditions with if–else in Go?
Yes, you can chain conditions using
else if to check many cases. Example:<br>if x > 10 {
fmt.Println("big")
} else if x == 10 {
fmt.Println("equal")
} else {
fmt.Println("small")
}Click to reveal answer
beginner
What happens if the if condition is false and there is no else block?
If the
if condition is false and there is no else, the program just skips the if block and continues running the next code.Click to reveal answer
What keyword starts an if condition in Go?
✗ Incorrect
The keyword
if is used to start a condition check in Go.What does the else block do in an if–else statement?
✗ Incorrect
The
else block runs only when the if condition is false.Which of these is the correct way to write an if statement in Go?
✗ Incorrect
Go uses
if with condition and curly braces for the code block, no extra keywords like then or do.How do you check multiple conditions in Go?
✗ Incorrect
You chain conditions with
else if to check multiple cases in order.What happens if the if condition is true and there is an else block?
✗ Incorrect
When the if condition is true, only the if block runs; the else block is skipped.
Explain how an if–else statement controls the flow of a Go program.
Think about choosing between two paths based on a yes/no question.
You got /4 concepts.
Write a simple Go if–else statement that prints "Even" if a number is even, and "Odd" if it is odd.
Use x % 2 == 0 to check even numbers.
You got /4 concepts.