Concept Flow - If–else statement
Start
Evaluate condition
Execute 'if' block
End
Execute 'else' block
End
The program checks a condition. If true, it runs the 'if' block; otherwise, it runs the 'else' block.
let age = 18; if (age >= 18) { console.log('Adult'); } else { console.log('Minor'); }
| Step | Condition (age >= 18) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 18 >= 18 | true | if block | Adult |
| 2 | N/A | N/A | End | Program ends |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| age | 18 | 18 | 18 |
if (condition) {
// code runs if condition true
} else {
// code runs if condition false
}
Checks condition once, runs one block only.