Mandeyo
Mandeyo

Reputation: 181

What does this for loop condition mean in C?

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

Answers (3)

Gorik
Gorik

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

Fiddling Bits
Fiddling Bits

Reputation: 8861

  1. Set initial value of j to i
  2. Check 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.
  3. Perform body of for loop. At end, decrement j by 1
  4. Repeat step 2
  5. Exit Loop

Upvotes: 0

suvojit_007
suvojit_007

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

Related Questions