StudyBrixFree worksheets, study guides and courses

Computer science · Grades 6–10

Trace a loop with a step

The upper limit is inclusive in the pseudocode here.

Make a worksheet

The key idea

The upper limit is inclusive in the pseudocode here.

count = floor((last − first)/step) + 1

Worked examples

FOR i FROM 14 TO 144 INCLUSIVE STEP 5: print i. How many numbers are printed?

(144 − 14)/5 + 1 = 27

27

FOR i FROM 7 TO 49 INCLUSIVE STEP 3: print i. How many numbers are printed?

(49 − 7)/3 + 1 = 15

15

Try it yourself

  1. FOR i FROM 6 TO 45 INCLUSIVE STEP 3: print i. How many numbers are printed?

  2. FOR i FROM 2 TO 134 INCLUSIVE STEP 6: print i. How many numbers are printed?

Check your understanding

Answers and marking notes
  1. 14

    (45 − 6)/3 + 1 = 14

  2. 23

    (134 − 2)/6 + 1 = 23

Learning preview · teacher review required. Grade bands are approximate, not official curriculum alignment.