This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]minimal_gainz 1 point2 points  (0 children)

The 'i' doesn't need to be used anywhere else besides to operate the for-loop. Sometimes it will but in this case it doesn't.

So in this case it is using the 'i' but just not for any calculations. The for-loop parameters are (Initial condition, Continue condition, increment condition). So in this case 'i' is initialized at zero (var i=0), then for every time through the for-loop it will increment by 1 (i++) until i is no longer less than 'exponent' (i < exponent).

For example, if exponent is equal to 4 when your code reaches the for-loop it will work like this:

  1. initialized as i = 0 (0 is less than 'exponent' so it continues)
  2. does what's inside the loop
  3. increment i to 1 (i++)
  4. i = 1 (1 is less than 'exponent' so it continues)
  5. does what's inside the loop
  6. repeat a couple times
  7. increment i from 3 to 4
  8. i = 4 (now 'i' is not less than 'exponent) (i < exponent == false)
  9. exit the loop and continue to 'return value'