Cp1 Lab 3 Mid Reviewer
Cp1 Lab 3 Mid Reviewer
Cp1 Lab 3 Mid Reviewer
Main topics:
• The Increment and Decrement Operators
• The while Loop
• Using the while Loop for Input Validation
• The do-while Loop
• The for Loop
• Running Totals and Sentinel Values
Note: Java Switch Statements
Instead of writing many if..else statements, you can use the switch
statement.
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
The Increment and Decrement Operators
• Example: IncrementDecrement.java
Differences Between Prefix and Postfix
while(condition)
{
statements;
}
true
boolean
statement(s)
expression?
false
Infinite Loops
while (condition)
{
statement;
statement;
statement;
}
The while Loop for Input Validation
statement(s)
true
boolean
expression?
false
The for Loop
boolean true
statement(s) update
expression?
false
The Sections of The for Loop
Sample Code: