Flow and Data
Branches
Choosing a Path
An if statement chooses which block runs. The condition is a logical value computed from current data.
Program
Play the script to watch a score choose the passing branch.
branches.R
score <- 82
if (score >= 80) {
grade <- "pass"
} else {
grade <- "retry"
}
cat(grade, "\n", sep = "")
if
`if (condition)` runs the following block only when the condition is `TRUE`.
comparison
`score >= 80` returns a logical value.
else
`else` gives the fallback path when the condition is `FALSE`.