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?

21st Sep 2021, 11:30 AM
TeaserCode
2 Réponses
+ 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 } }
21st Sep 2021, 11:36 AM
Ipang
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...
21st Sep 2021, 11:37 AM
Jayakrishna 🇮🇳