Conditional Statements Flashcards
An __? statement checks a condition and will execute a task if that condition evaluates to be __?.
An if statement checks a condition and will execute a task if that condition evaluates to true.
____? and ___? statements make binary decisions and execute different code blocks based on a provided condition.
if…else statements make binary decisions and execute different code blocks based on a provided condition.
We can add more ____? using ___? statements.
We can add more conditions using else if statements.
Comparison operators, including __,__, __,__,__, and ___? can compare two values
Comparison operators, including
<, >, <=, >=, ===, and !==
can compare two values
The logical and operator, __?, or __?, checks if both provided expressions are truthy.
The logical and operator,
&&, or “and”,
checks if both provided expressions are truthy.
The logical operator, _____? checks if either provided expression is truthy.
The logical operator ||, or “or”, checks if either provided expression is truthy. true || false; // true 10 > 5 || 10 > 20; // true false || false; // false 10 > 100 || 10 > 20; // false
The ___? operator, ___?, switches the truthiness and falsiness of a value.
The
bang operator, !,
switches the truthiness and falsiness of a value.
There is also a short-hand if else, which is known as the _____? operator because it consists of three operands. The _____ operator allows for a compact syntax in the case of binary (choosing between two choices) decisions. It accepts a condition followed by a __ operator, and then two expressions separated by a __ If the condition evaluates to truthy, the first expression is executed, otherwise, the second expression is executed.
There is also a short-hand if else, which is known as the ternary operator The ternary operator allows for a compact syntax in the case of binary (choosing between two choices) decisions. It accepts a condition followed by a ? operator, and then two expressions separated by a :. If the condition evaluates to truthy, the first expression is executed, otherwise, the second expression is executed.
Example
let price = 10.5;
let day = “Monday”;
day === “Monday” ? price -= 1.5 : price += 1.5;
Java ____? Statements
Use the ____? statement to select one of many code blocks to be executed.
The ____? keyword stops the remaining cases from being checked and executed in a ___?
Java Switch Statements Use the switch statement to select one of many code blocks to be executed. switch(expression) { case x: // code block break; case y: // code block break; default: // code block }