Is it possible to fit in a ternary operator as the termination in a for loop?
问题 So, I just want to know if its possible to slip in any code or a ternary operator inside the termination bit of a for loop. If it is possible, could you provide an example of a ternary operator in a for loop? Thanks! for (initialization; termination; increment) { statement(s) } 回答1: The termination clause in the for statement (if supplied - it's actually optional) can be any expression you want so long as it evaluates to a boolean . It must be an expression , not an arbitrary code block. 回答2: