Friday, 26 July 2019

Processing: Ternary operator


Ternary operator( ?: )
   Returns one of two expressions depending on a condition.

    Syntax
       test ? expression1 : expression2
Returns expression1 if the “test” condition evaluates to true other wise returns expression 2.

Operators.pde
int a = 100;

int flag = a>10 ? 1 : 0;
println(flag);

flag = a>1000 ? 1 : 0;
println(flag);


Output
1
0

Observation
See the statement “flag = a>10 ? 1 : 0”, a>10 is true, so 1 is returned and assigned to the flag,

Previous                                                    Next                                                    Home

No comments:

Post a Comment