WHILE NotSolved
Instructions here
FOR i ← 1 TO 5
Instructions here
ENDFOR
Instructions here
ENDWHILE
NotSolved = True # You can change this condition as needed
while NotSolved:
# Instructions here
print("Doing something before the loop")
for i in range(1, 6): # 1 to 5 inclusive
# Instructions inside FOR loop
print(f"Iteration {i} inside FOR loop")
# Instructions after FOR loop
print("Doing something after the loop")
# Example condition to stop the while loop
NotSolved = False # Change this when the problem is solved
while NotSolved: → Keeps looping until NotSolved becomes False.for i in range(1, 6): → Loops from 1 to 5 inclusive.
IF GameWon THEN
Instructions here
IF Score > HighScore THEN
Instructions here
ENDIF
Instructions here
ENDIF
GameWon = True # Example condition
Score = 120
HighScore = 100
if GameWon:
# Instructions here
print("You won the game!")
if Score > HighScore:
# Instructions inside the nested IF
print("New high score!")
HighScore = Score
# Instructions after the nested IF
print("Returning to main menu...")
if GameWon: → Outer condition checks if the game is won.if Score > HighScore: → Inner condition only runs if the outer one is true.if.
Selection means making decisions in a program — choosing which part of the code to run based on a condition.
It allows the program to select different paths of execution depending on whether something is True or False.
score = 85
if score >= 50:
print("You passed!")
score = 45
if score >= 50:
print("You passed!")
else:
print("You failed.")
score = 75
if score >= 90:
print("Grade: A")
elif score >= 70:
print("Grade: B")
else:
print("Grade: C")
| Type | What it does |
|---|---|
| Variable declaration | Create storage for data (score = 0) |
| Constant declaration | Store fixed values (PI = 3.14159) |
| Assignment | Change a variable’s value (score = 10) |
| Iteration | Repeat actions (for, while) |
| Selection | Choose actions (if, else) |
| Subroutine | Group actions (def function():) |
PI = 3.14159 # constant declaration
radius = 5 # variable declaration
area = PI * radius**2 # assignment
def display_area(area): # subroutine
print("Area:", area)
if area > 50: # selection
print("Big circle!")
else:
print("Small circle!")
for i in range(3): # iteration
display_area(area)