size

k

k >= 0

j  > ary[k]

j

 

7

5

True

 

10

1st iteration

 

4

True

10 >  8 True

8

2nd iteration

 

3

True

 8 > 15 False

 

3rd iteration

 

2

True

 8 >  6 True

6

4th iteration

 

1

True

 6 >  7 False

 

5th iteration

 

0

True

 6 >  3 True

3

6th iteration

 

-1

FALSE

 3 >  5 False

 

 

 

In this loop we walk through the array from the end to the beginning, using k as the walking index.  With each iteration, the current value of j is compared with the current value in ary (value with index k).  If the current value in ary is smaller, j is set to this value.  When we get to the beginning of ary, j holds the smallest value.