Abh*_*eet 2 c++ for-loop ternary-operator conditional-statements
在for循环条件中使用三元运算是一种好习惯.我问这个是因为我遇到过这样的情况:三元操作将解决我在循环条件中的问题.
例如:
for( short i = 0 ; i < count ; i++ ){
for( short j = 0 ; j < ( ( x[i] < y[i] ) ? x[i] : y[i] ) ; j++ ){ //Here I am using ternary operation at for loop condition place
//.....
//.....Some Code Here .......
//.....
}
}
Run Code Online (Sandbox Code Playgroud)
我会去min(x[i], y[i]),因为它更清楚,但我没有看到您的代码立即出现问题.