FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
      Language \ Environment \ Libraries \ Comparison
 
   
   
Abridged (A-Z) \ Complete (A-Z)  
   
  Reference for Processing (BETA) version 91+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.  
Name  

?: (conditional)

   
Examples  
int s = 0; 
for(int i=5; i<100; i+=5) { 
  s = (i < 50) ? 0 : 255; 
  stroke(s); 
  line(30, i, 80, i); 
} 

Description   A shortcut for writing an if() and else structure. If the condition evaluates to true, expression1 is evaluated and returned. If the condition evaluates to false, expression2 is evaluated and returned.

The following conditional:
condition : expression1 ? expression2

is equivalent to this structure:
if(condition) {
expression1
} else {
expression2
}
   
Syntax  
condition ? expression1 : expression2
   
Parameters  
condition   any valid expression which evaluates to true or false

expression1   any valid expression

expression2   any valid expression

   
Returns   Variable, dependent on the datatype of the expressions
   
Usage   Web & Application
   
Related   if()
else
 
 






   
 
Updated: Fri Jul 15 16:35:35 PDT 2005
 
 








Creative Commons License
 
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info