Reference+
Name
else
Description
Extends the if structure allowing the program to choose between two or more blocks of code. It specifies a block of code to execute when the expression in if is false.
Examples
size(400, 400); for (int i = 20; i < 380; i += 20) { if (i < 140) { line(120, i, 320, i); } else { line(80, i, 360, i); } }
size(400, 400); for (int i = 20; i < 380; i += 20) { if (i < 140) { line(120, i, 320, i); } else if (i < 260) { line(80, i, 360, i); } else { line(0, i, 400, i); } }
Syntax
if (expression) {
statements
} else {
statements
}
if (expression) {
statements
} else if (expression) {
statements
} else {
statements
}
Parameters
expression
any valid expression that evaluates to true or falsestatements
one or more statements to be executed
Related
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.