Created: 2023-01-22 15:50
Status: #concept
Subject: Programming Logic
Tags: C JavaScript Python Boolean Operator
Conditional Statements
Description
Conditional Statements control Program Flow with the use of Boolean Expressions.
if...else
if (condition) {
/* code to run if condition is true */
} else if (another_condition) {
/* code to run if another_condition is true */
} else {
/* run this code if everything above is false */
}
switch (expression) { case value: }
switch (expression) {
case choice1:
run this code
break;
case choice2:
run this code instead
break;
// include as many cases as you like
default:
actually, just run this code
}
- Ternary Operator
condition ? exprIfTrue : exprIfFalse
const greeting = isBirthday
? 'Happy birthday Mrs. Smith — we hope you have a great day!'
: 'Good morning Mrs. Smith.';