About Lesson
if, elif, else
- if Statement: Executes a block of code if a condition is true.
pythonif condition: # code to execute
- elif Statement: Short for “else if,” it checks another condition if the previous conditions are false.
pythonif condition1: # code to execute elif condition2: # code to execute
- else Statement: Executes a block of code if none of the previous conditions are true.
pythonif condition1: # code to execute elif condition2: # code to execute else: # code to execute
for, while Loops
- for Loop: Iterates over a sequence (e.g., list, tuple, string) and executes a block of code for each item.
pythonfor item in sequence: # code to execute
- while Loop: Repeats a block of code as long as a condition is true.
pythonwhile condition: # code to execute