Conditions
-
Evaluates an expression, performs action based on that expression.
-
if statement is one of the most common.
-
Use with curly braces most of the time, optional for one line.
-
Trust me, use curly braces all of the time.
if (day.equals("Saturday"))
{
System.out.println("I am off to Woody's to have
a Grolsch!");
}
-
else and else if (optional) follows the if, and is evaluated
if the if condition is false.
if (day.equals("Saturday"))
{
System.out.println("I am off to Woody's to have
a Grolsch!");
} else if (day.equals("Friday")) {
System.out.println("I am off to Christie's to
grab
a Hudy Delight.");
} else {
System.out.println("Back to work(s)");
}
Conditional Operation
Home
slide adapted from Internet II.