Reputation: 181
I have a problem with figuring out what the following loop means as i'm new to C. I have some value of temp and an array v. Middle part evaluates to true or false, so i am really confused.
for( j=i ; j>0 && temp<v[j-1] ; j--){...}
Upvotes: 0
Views: 77
Reputation: 21
This line is pretty simple:
Iterate 'i'
elements of array 'v'
in backward direction while values are less than 'temp'.
When value appear as more or equal than 'temp' or 'j'
went to zero then exit the loop.
Upvotes: 2
Reputation: 8861
j
to i
j
to see if it is greater than 0
and check temp
to see if it is less than value of element in array v
at index j - 1
. If both cases are true, proceed to step 3; if either case is false, proceed to step 5.for
loop. At end, decrement j
by 1
Upvotes: 0
Reputation: 1728
Execute the body of the for
loop while both conditions j>0
and temp<v[j-1]
are true
.
Here j=i,i-1,.......,2,1,0
Upvotes: 0