0
How to interpret expression: for(int j=(i? i + 1:i + 2); j < size; j++)?
How can I write this expression with if-else statement?
2 Answers
+ 1
Assuming there is an outer loop for <i>
for( int i, j ; ... ; ... )
{
if( i )
j = i + 1;
else
j = i + 2;
for( ; j < size ; j++ )
{
// inner loop body
}
}
0
Assignment to j is a ternary expression which is alternative one line expression to if-else statement..
Expand i assignment before loop and use j=i then.
If you not aware of ternary expression, then look at once in lesson..
Hope it helps...