简体   繁体   中英

What does this for loop condition mean in C?

我在弄清楚以下循环的含义时遇到了问题,因为我是C的新手。我有一些temp值,一个数组v。中间部分的值为true或false,所以我很困惑。

for( j=i ; j>0 && temp<v[j-1] ; j--){...}

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.

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

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM