mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 18:10:43 +01:00
119 lines
2.3 KiB
XML
119 lines
2.3 KiB
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
<root>
|
|
<name>switch()</name>
|
|
|
|
<category>Control</category>
|
|
|
|
<subcategory>Conditionals</subcategory>
|
|
|
|
<usage>Web & Application</usage>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
int num = 1;
|
|
|
|
switch(num) {
|
|
case 0:
|
|
println("Zero"); // Does not execute
|
|
break;
|
|
case 1:
|
|
println("One"); // Prints "One"
|
|
break;
|
|
}
|
|
</code>
|
|
</example>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
char letter = 'N';
|
|
|
|
switch(letter) {
|
|
case 'A':
|
|
println("Alpha"); // Does not execute
|
|
break;
|
|
case 'B':
|
|
println("Bravo"); // Does not execute
|
|
break;
|
|
default: // Default executes if the case labels
|
|
println("None"); // don't match the switch parameter
|
|
break;
|
|
}
|
|
</code>
|
|
</example>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
// Removing a "break" enables testing
|
|
// for more than one value at once
|
|
|
|
char letter = 'b';
|
|
|
|
switch(letter) {
|
|
case 'a':
|
|
case 'A':
|
|
println("Alpha"); // Does not execute
|
|
break;
|
|
case 'b':
|
|
case 'B':
|
|
println("Bravo"); // Prints "Bravo"
|
|
break;
|
|
}
|
|
</code>
|
|
</example>
|
|
|
|
|
|
<description>
|
|
Works like an <b>if else</b> structure, but <b>switch()</b> is more convenient when you need to select between three or more alternatives. Program controls jumps to the case with the same value as the expression. All remaining statements in the switch are executed unless redirectly by a <b>break</b>. Only primitive datatypes which can convert to an integer (byte, char, and int) may be used as the <b>expression</b> parameter. The default is optional.
|
|
</description>
|
|
|
|
<syntax>
|
|
switch(<c>expression</c>)
|
|
{
|
|
case <c>label</c>:
|
|
<c>statements</c>
|
|
case <c>label</c>: // Optional
|
|
<c>statements</c> // "
|
|
default: // "
|
|
<c>statements</c> // "
|
|
}
|
|
</syntax>
|
|
|
|
<parameter>
|
|
<label>expression</label>
|
|
<description>byte, char, or int</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>label</label>
|
|
<description>byte, char, or int</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>statements</label>
|
|
<description>one or more statements to be executed</description>
|
|
</parameter>
|
|
|
|
<returns></returns>
|
|
|
|
<related>
|
|
case
|
|
default
|
|
break
|
|
if()
|
|
else
|
|
</related>
|
|
|
|
<availability>1.0</availability>
|
|
|
|
<type>Function</type>
|
|
|
|
<partof>Java</partof>
|
|
|
|
<level>extended</level>
|
|
|
|
|
|
</root>
|