Concept Flow - If-else statements
Start
Evaluate Condition
Execute If Block
End If-Else
Execute Else Block
End If-Else
The program checks a condition. If true, it runs the 'if' part; if false, it runs the 'else' part.
if (balance >= amount) { send(amount); } else { revert("Insufficient funds"); }
| Step | Condition (balance >= amount) | Result | Branch Taken | Action |
|---|---|---|---|---|
| 1 | balance=100, amount=50 | True | If | send(50) called |
| 2 | balance=30, amount=50 | False | Else | revert("Insufficient funds") called |
| Variable | Start | After Step 1 | After Step 2 |
|---|---|---|---|
| balance | 100 | 100 | 30 |
| amount | 50 | 50 | 50 |
If-else statements check a condition.
If true, run the 'if' block.
If false, run the 'else' block.
Used to control program flow based on conditions.
Syntax: if (condition) { ... } else { ... }