• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/8

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

8 Cards in this Set

  • Front
  • Back
?: (conditional)
A shortcut for writing an if and else structure. The conditional operator, ?: is sometimes called the ternary operator, an operator that takes three arguments. If the test evaluates to true, expression1 is evaluated and returned. If the condition evaluates to false, expression2 is evaluated and returned.

The following conditional expression:
result = test ? expression1 : expression2

is equivalent to this structure:
if (test) {

result = expression1

} else {

result = expression2

}

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

Syntax
test ? expression1 : expression2
break
Ends the execution of a structure such as switch, for, or while and jumps to the next statement after.

Example
char letter = 'B';

switch(letter) {
case 'A':
println("Alpha"); // Does not execute
break;
case 'B':
println("Bravo"); // Prints "Bravo"
break;
default:
println("Zulu"); // Does not execute
break;
}
case
Denotes the different labels to be evaluated with the parameter in the switch structure.

Example
char letter = 'B';

switch(letter) {
case 'A':
println("Alpha"); // Does not execute
break;
case 'B':
println("Bravo"); // Prints "Bravo"
break;
default:
println("Zulu"); // Does not execute
break;
}

Syntax
case label: statements
continue
When run inside of a for or while, it skips the remainder of the block and starts the next iteration.

Example
for (int i = 0; i < 100; i += 10) {
if (i == 70) { // If 'i' is 70,
continue; // skip to the next iteration,
} // therefore not drawing the line.
line(i, 0, i, height);
}
default
Keyword for defining the default condition of a switch. If none of the case labels match the switch parameter, the statement(s) after the default syntax are executed. Switch structures don't require a default.

Example
char letter = 'F';

switch(letter) {
case 'A':
println("Alpha"); // Does not execute
break;
case 'B':
println("Bravo"); // Does not execute
break;
default:
println("Zulu"); // Prints "Zulu"
break;
}

Syntax
default: statements
else
Extends the if structure allowing the program to choose between two or more block of code. It specifies a block of code to execute when the expression in if is false.

Example
for (int i = 5; i < 95; i += 5) {
if (i < 35) {
line(30, i, 80, i);
} else {
line(20, i, 90, i);
}
}

Syntax
if (expression) {
statements
} else {
statements
}

if (expression) {
statements
} else if (expression) {
statements
} else {
statements
}
if
Allows the program to make a decision about which code to execute. If the test evaluates to true, the statements enclosed within the block are executed and if the test evaluates to false the statements are not executed.

Example
for (int i = 5; i < height; i += 5) {
stroke(255); // Set the color to white
if (i < 35) { // When 'i' is less than 35...
stroke(0); //...set the color to black
}
line(30, i, 80, i);
}

Syntax
if (test) {
statements
}
switch
Works like an if else structure, but switch 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 redirected by a break. Only primitive datatypes which can convert to an integer (byte, char, and int) may be used as the expression parameter. The default is optional.

Example
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;
}

Syntax
switch(expression)
{
case label:
statements
case label: // Optional
statements // "
default: // "
statements // "
}