Concept Flow - Logical (boolean) type
Assign TRUE or FALSE
Use in condition or variable
Evaluate condition
Execute
End
This flow shows how a logical value (TRUE or FALSE) is assigned and used in conditions to decide which code runs.
x <- TRUE if (x) { print("Yes") } else { print("No") }
| Step | Action | Expression | Result | Output |
|---|---|---|---|---|
| 1 | Assign x | x <- TRUE | x = TRUE | |
| 2 | Evaluate if condition | if (x) | TRUE | |
| 3 | Execute if block | print("Yes") | prints Yes | Yes |
| 4 | End | No more code | - |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| x | undefined | TRUE | TRUE | TRUE |
Logical (boolean) type in R:
- Values: TRUE or FALSE
- Stored in variables like x <- TRUE
- Used in conditions: if (x) { ... } else { ... }
- Controls which code runs based on TRUE/FALSE
- Essential for decision making in programsresult <- 5 > 3 print(result)
flag <- TRUE
if flag == TRUE {
print("Yes")
}nums <- c(0, 1, 2, 3, 0), which R expression correctly creates a logical vector indicating which elements are non-zero?Pass the test and this pattern moves unknown