Concept Flow - If statement
Start
Evaluate condition
Execute if-block
Continue
Skip if-block
Continue
The program checks a condition. If true, it runs the code inside the if-block. If false, it skips it and continues.
let x = 10; if (x > 5) { console.log('x is greater than 5'); }
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | true | Execute if-block | x is greater than 5 printed |
| 2 | End of if statement | - | Continue | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | 10 | 10 | 10 |
If statement syntax:
if (condition) {
// code runs if condition is true
}
Checks condition once.
Runs code only if true.
Skips code if false.