Program Control Flashcards
Selection statements
If and Switch
Iteration Statements
For, While, Do-While Loops
Jump Statements
Break, Continue & Return
If Statement Syntax
if (condition) { ... } else { ... }
If-Else If-Else Syntax
If (condition) {...} Else If (condition) {...} Else {...}
Switch Statement Uses
Value of an expression is tested against a list of scenarios. When a match is found, that statement sequence is executed.
Enables a program to select among alternatives.
Switch Statement Syntax
Switch(expression) { case constant1: Statement sequence break; case constant2: statement sequence break; default: statement sequence }
Valid types for switch expressions
byte, short, int, char, String
Is the default switch statement required?
No, it is optional. No action takes place if all matches fail.
Can you nest Switch Statements?
Yes
For Loop Uses
Performing a known number of iterations
For Loop Syntax
for (initialization; Boolean condition; iteration)
{
statement sequence
}
While Loop Uses
An unknown number of iterations
While Loop Syntax
While (condition)
statement;
Do-While Loop Uses
When at least one iteration is necessary in an unknown number of iterations