Concept Flow - Why logic controls execution
Start Transaction
Evaluate Condition
Execute
Update State
End Transaction
This flow shows how logic (conditions) decide which parts of blockchain code run, controlling state changes.
if (balance >= amount) { balance -= amount; recipient += amount; } else { revert("Insufficient funds"); }
| Step | Condition (balance >= amount) | Action Taken | Balance | Recipient | Output |
|---|---|---|---|---|---|
| 1 | 100 >= 50 | Yes branch executed | 100 | 0 | None |
| 2 | Balance updated: 100 - 50 | balance = 50 | 50 | 0 | None |
| 3 | Recipient updated: 0 + 50 | recipient = 50 | 50 | 50 | None |
| 4 | End | Transaction successful | 50 | 50 | None |
| 5 | If balance was less, revert called | No branch executed | 100 | 0 | Error: Insufficient funds |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| balance | 100 | 50 | 50 | 50 |
| recipient | 0 | 0 | 50 | 50 |
Logic controls execution by deciding which code runs. If conditions are true, code inside runs and changes state. If false, alternate code runs or transaction reverts. This ensures blockchain state updates only when rules allow. Without logic, all code would run blindly, causing errors.