C++: Multiple exit conditions in for loop (multiple variables): AND -ed or OR -ed?

前端 未结 2 696
灰色年华
灰色年华 2021-02-12 13:16

For loops and multiple variables and conditions.

I am using a for loop to set source and destination indexes to copy items in an array.

for(int src = 0,          


        
2条回答
  •  梦谈多话
    2021-02-12 13:47

    The comma operator evaluates the first expression and discards the result. Then it evaluates the second and that is what is the value tested in the if. You will find that your condition is not && nor || but behaves exactly like if(dst >= 0). Sometimes the form is useful for changing a value at the end of a loop before the test is carried out.

提交回复
热议问题