Concept Flow - If statement
Start
Evaluate condition
Execute if-block
Continue
Skip if-block
Continue
The program checks a condition. If true, it runs the code inside the if-block. If false, it skips it and continues.
package main import "fmt" func main() { x := 10 if x > 5 { fmt.Println("x is greater than 5") } }
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | True | Execute if-block | x is greater than 5 |
| 2 | End of if statement | N/A | Continue |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | undefined | 10 | 10 |
If statement syntax:
if condition {
// code runs if condition is true
}
Checks condition once.
Runs code block only if true.
Skips block if false.if statement do in Go?if condition { code } without parentheses or 'then'.package main
import "fmt"
func main() {
x := 5
if x > 3 {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}package main
import "fmt"
func main() {
x := 10
if x > 5
fmt.Println("Big")
}n. Which code correctly uses if statements to do this?Pass the test and this pattern moves unknown