Files
processing4/web/reference/API/conditional.xml
2005-01-27 06:48:42 +00:00

67 lines
1.5 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>?: (conditional)</name>
<category>Control</category>
<subcategory>Conditionals</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image></image>
<code>
int s = 0;
for(int i=5; i&lt;100; i+=5) {
s = (i &lt; 50) ? 0 : 255;
stroke(s);
line(30, i, 80, i);
}
</code>
</example>
<description>
A shortcut for writing an <b>if()</b> and <b>else</b> structure. If the <b>condition</b> evaluates to <b>true</b>, <b>expression1</b> is evaluated and returned. If the <b>condition</b> evaluates to <b>false</b>, <b>expression2</b> is evaluated and returned.<br /><br />The following conditional: <br /><pre>condition : expression1 ? expression2</pre><br />is equivalent to this structure: <br /><pre>if(condition) {<br /> expression1 <br />} else { <br /> expression2 <br />}</pre>
</description>
<syntax>
<c>condition</c> ? <c>expression1</c> : <c>expression2</c>
</syntax>
<parameter>
<label>condition</label>
<description>any valid expression which evaluates to true or false</description>
</parameter>
<parameter>
<label>expression1</label>
<description>any valid expression</description>
</parameter>
<parameter>
<label>expression2</label>
<description>any valid expression</description>
</parameter>
<returns>Variable, dependent on the datatype of the expressions</returns>
<related>
if()
else
</related>
<availability>1.0</availability>
<type>Structure</type>
<partof>PDE</partof>
<level>Extended</level>
</root>