Lesson 07 of 55
8 mins readPython Conditional Branching: if, then, elseif & else
In Plain English
In Lua, conditionals begin with `if condition then`, can have multiple `elseif condition then` branches, an optional `else`, and must end with the `end` keyword.
Deep Dive: How It Works
Keyword then: Condition expressions must be followed by the `then` keyword.
Spelling: The keyword is `elseif` (one word, without spaces or hyphens).
Terminator: All control flow blocks terminate with `end`.
Core Rules to Remember

then ... end Block: Every if statement requires `then` after the condition and terminates with `end`.

elseif Keyword: Single word `elseif` for cascading conditions.
Live Interactive Example
Hit Run Code to see it liveGrading Logic in Lua
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
Output Console
Click "Run Code" to view the rendered output.
How it works: score 85 matched the (score >= 80) branch.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Check CPU Temperature
Declare `local temp = 82`.
If `temp > 80`, print `"Warning: Overheating"`. Otherwise print `"Temp: OK"`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.