Concept Flow - If-else statements
Evaluate condition
Is condition TRUE?
No→Execute else block
Yes
Execute if block
End
The program checks a condition. If true, it runs the 'if' part; if false, it runs the 'else' part, then continues.
x <- 7 if (x > 5) { result <- "big" } else { result <- "small" }
| Step | Condition (x > 5) | Result | Branch Taken | Variable 'result' |
|---|---|---|---|---|
| 1 | 7 > 5 | TRUE | if block | "big" |
| 2 | End of if-else | - | - | "big" |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | 7 | 7 | 7 |
| result | undefined | "big" | "big" |
If-else statements in R:
if (condition) {
# code if TRUE
} else {
# code if FALSE
}
Runs one block based on condition truth.
Useful for decision making.