Conditional Statements
🔹 Use if-else to make decisions in code.
age = 18
if age >= 18:
print("You can vote")
else:
print("You cannot vote")
🔸 Use if-elif-else when there are multiple conditions.
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
else:
print("Grade C")
Loops
🔹 Loops help in repeating tasks.
🔸 For Loop
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
🔸 While Loop
count = 1
while count <= 5:
print(count)
count += 1
Break and Continue
🔹 Use break to exit a loop early.
for num in range(1, 10):
if num == 5:
break
print(num)
🔹 Use continue to skip an iteration.
for num in range(1, 6):
if num == 3:
continue
print(num)