CSC300 / CSC402: While loop version [5/14] | ![]() ![]() ![]() |
Code:
For // list==[5,11,5,5], i==0, result==0 // list==[5,11,5,5], i==1, result==1 // list==[5,11,5,5], i==2, result==1 // list==[5,11,5,5], i==3, result==2 // list==[5,11,5,5], i==4, result==3 More abstractly: // list[i..]==[5,11,5,5], result==0 // list[i..]==[11,5,5], result==1 // list[i..]==[5,5], result==1 // list[i..]==[5], result==2 // list[i..]==[], result==3 This is a while loop. Execution enters the loop without first checking to see if it is necessary. |