Step 1: If-Else Statements
Conditionals allow your program to make decisions based on data.
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Enter your age: 20
You are an adult.
Step 2: For Loops
For loops are used to iterate over sequences like lists or ranges.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
apple
banana
cherry
Step 3: While Loops
While loops repeat as long as a condition is True.
count = 1
while count <= 5:
print("Count =", count)
count += 1
Count = 1
Count = 2
Count = 3
Count = 4
Count = 5
Step 4: Break & Continue
Use break to exit a loop early and continue to skip the current iteration.
for i in range(1, 6):
if i == 3:
continue # skip 3
print(i)
1
2
4
5
Step 5: PyCharm Project Example – Loops
Project layout and code demonstration:
MyPythonProject
├── loops.py
├── data.txt
└── requirements.txt
# loops.py
numbers = [1, 2, 3, 4, 5]
for n in numbers:
if n == 3:
continue
print(n)
1
2
4
5
✔ End of Day 3 – Conditionals and loops understood and tested. You can now control the flow of your programs!