Flow-Control-and-Functions-in-Python
Flow-Control-and-Functions-in-Python
by Farhaaann
Decision Making with if Statements
if Statement if...else Statement if...elif...else Statement
Executes code if a condition is true. Runs one block if true, another if false. Checks multiple conditions in order.
Example: if x > 0: print("Positive") Example: if x % 2 == 0: print("Even") Example: if score >= 90: print("A") elif
else: print("Odd") score >= 80: print("B") else: print("C")
Iteration with for Loops
for Loop Basics range() Function Typical Uses
Iterate over sequences like lists or Generate sequences with start, Process lists and repeat actions
strings. stop, step. efficiently.
Iteration with while Loops
while Loop Loop with else Applications
Repeat code as long as a condition Run extra code if the loop ends Best for conditional repetition and
remains true. without break. waiting for events.
Nested Loops
A loop inside another loop allows complex iterations.