FOR LOOP
REPEAT · COUNT · PRINT
prostudypk.com
Table of 5 with a Loop
for
i
in
range
(1, 11):
print
(
"5 x"
, i,
"="
, 5*i)
VARIABLE i
5 * i
CONDITION i ≤ 10
OUTPUT
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
iterations
2 lines
of code
lines printed
1. range(start, stop)
range(1, 11) → 1, 2, 3 … 10
the stop value (11) is not included
2. Progress
Without a loop you would write 10 print lines
3. Remember
Loop = doing one task again and again
The body is always indented
MATRIC COMPUTER · PROGRAMMING · PUNJAB BOARDS
‹ Labs
↺
❚❚
1×
Next ›