Concept Flow - If–else statement
Evaluate condition
Condition true?
No→Execute else block
Yes
Execute if block
End
The program checks a condition. If true, it runs the 'if' block; otherwise, it runs the 'else' block.
package main import "fmt" func main() { x := 10 if x > 5 { fmt.Println("x is greater than 5") } else { fmt.Println("x is 5 or less") } }
| Step | Condition | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | x > 5 (10 > 5) | true | if block | "x is greater than 5" printed |
| 2 | End of if-else | N/A | Program ends | No further output |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | undefined | 10 | 10 |
if condition {
// code runs if condition true
} else {
// code runs if condition false
}
Checks condition once, runs one block only.if-else statement do in Go?package main
import "fmt"
func main() {
x := 5
if x > 10 {
fmt.Println("Greater")
} else {
fmt.Println("Smaller or equal")
}
}package main
import "fmt"
func main() {
x := 7
if x > 5
fmt.Println("Big")
else
fmt.Println("Small")
}Pass the test and this pattern moves unknown