Recall & Review
beginner
What is the purpose of an
if statement in Go?An
if statement lets the program decide to run some code only if a condition is true. It's like choosing a path based on a yes/no question.Click to reveal answer
beginner
How do you write a simple
if statement in Go?You write
if condition { /* code to run if true */ }. The condition follows directly after if without parentheses, and the code to run is inside curly braces.Click to reveal answer
beginner
Can you use an
if statement without an else in Go?Yes! You can run code only when the condition is true and do nothing if it is false. The
else part is optional.Click to reveal answer
beginner
What happens if the
if condition is false and there is no else block?The program skips the code inside the
if block and continues running the rest of the program.Click to reveal answer
beginner
How do you write an
if-else statement in Go?You write
if condition { /* code if true */ } else { /* code if false */ }. This runs one block or the other depending on the condition.Click to reveal answer
What does an
if statement do in Go?✗ Incorrect
An
if statement checks a condition and runs code only when it is true.Which symbol is used to start the code block after an
if condition in Go?✗ Incorrect
Curly braces
{ } are used to group the code that runs if the condition is true.Is the
else part mandatory after an if in Go?✗ Incorrect
The
else block is optional; you can have just an if statement.What happens if the
if condition is false and there is no else?✗ Incorrect
If the condition is false and no
else exists, the code inside if is skipped.How do you write an
if-else statement in Go?✗ Incorrect
The correct syntax is
if condition { } else { } without extra words or symbols.Explain how an
if statement controls the flow of a Go program.Think about how you decide to do something only if a condition is met.
You got /4 concepts.
Write the syntax of a simple
if statement in Go and describe each part.Remember the shape of the code with braces and the condition.
You got /4 concepts.