How many times does a (for) loop iterate? [closed]

We need to know what the values of start, end, and step are.

if:
  start = 0;
  end = 10;
  step = 1;

It would loop 11 times, each time adding 1 to the previous value of i until it is <= 10. (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)

if:
  start = 0;
  end = 10;
  step = 2;

It would loop 6 times, each time adding 2 to the previous value of i until it is <= 10. (0, 2, 4, 6, 8, 10)

if:
  start = 10;
  end = 100;
  step = 10;

It would loop 10 times, each time adding 10 to the previous value of i until it is <= 100. (10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

And so on.

Leave a Comment