0
0
Goprogramming~5 mins

If statement in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARuns code only if a condition is true
BRuns code repeatedly
CDefines a function
DDeclares a variable
Which symbol is used to start the code block after an if condition in Go?
A[ ]
B( )
C{ }
D< >
Is the else part mandatory after an if in Go?
ANo, it's optional
BOnly inside loops
COnly if the condition is false
DYes, always
What happens if the if condition is false and there is no else?
AProgram crashes
BCode inside <code>if</code> runs anyway
CProgram asks for input
DCode inside <code>if</code> is skipped
How do you write an if-else statement in Go?
Aif (condition) then { } else { }
Bif condition { } else { }
Cif condition: { } else: { }
Dif condition -> { } else -> { }
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.