if Statement
noun
say it: “if STAYT-ment” /ɪf ˈsteɪtmənt/
Code that runs a block only when a condition is true, and skips it otherwise.
What does if Statement do in Java?
if Statement — A statement that runs code only when its condition is true.
class Venue {
boolean canEnter(int age) {
boolean isAdult = age >= 18;
boolean isSenior = age >= 65;
if (isAdult && !isSenior) {
return true;
}
return false;
}
}
In a sentence
- “I wrapped the discount in an if statement so it only applies when the total is over 100.”
Level: Novice · More Java terms at this level
Updated