Making Choices with if/else
Branch on conditions.
Code That Decides
Programs often need to choose a path. The if statement runs a block only when its condition is true, so your code can react to data. 🔀
Your First if
Write if, a condition, a colon, then an indented block. If the condition holds, Mojo runs the block; otherwise it skips it entirely.
if score > 90:
print("Top marks!")All lessons in this course
- Making Choices with if/else
- Looping with while
- Iterating with for and range
- break, continue, and Early Exit