ch6 Flashcards
why Use if
to specify a block of code to be executed, if a specified condition is true
why use Use else
to specify a block of code to be executed, if the same condition is false
why use else if
Use else if to specify a new condition to test, if the first condition is false
how we can test for the condtion easily
variable = (condition) ? expressionTrue : expressionFalse;
the difference between if and the easy way
int time = 20;
String result;
result = (time < 18) ? “Good day.” : “Good evening.”;
System.out.println(result);
nt time = 20; if (time < 18) { System.out.println("Good day."); } else { System.out.println("Good evening."); }
else if =switch +break
if =switch -break
true or false
true
Loops
Loops
Loops can execute a block of code as long as a specified condition is reached.
Loops are handy because they save time, reduce errors, and they make code more readable.
Java While Loop
The while loop loops through a block of code as long as a specified condition is true: