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 = 55 x 2 = 105 x 3 = 155 x 4 = 205 x 5 = 255 x 6 = 305 x 7 = 355 x 8 = 405 x 9 = 455 x 10 = 50 iterations 2 linesof 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 againThe body is always indented
MATRIC COMPUTER · PROGRAMMING · PUNJAB BOARDS
‹ Labs Next ›