Reputation: 335
for j = n − 1 to 1 step − 1 do
does this means for all j in [1 .. n-1] or [2 .. n-1] ?
Upvotes: 1
Views: 3455
Reputation: 48016
for j = n − 1 to 1 step − 1 do
is a countdown.
It will start at j and count down to 1 (inclusive).
So if j is 6, then it will go down 5, 4, 3, 2, 1.
twist: Now if your j is a negative value, then you should consider that it will go upto the min negative first, then rollover to the max positive and then count down to 1.
Upvotes: 3
Reputation: 44804
Seems pretty clear to me. That means it counts down from n-1 to 1.
Upvotes: 0
Reputation: 25074
If n=5 then the for loop is executed 4 times with J equal to 4 then 3, then 2, and finally 1 in that order
Upvotes: 1