### What Are Conditionals?
Conditionals evaluate expressions and execute different blocks of code depending on
whether a condition is **true** or **false**. The most common conditional
statements are:
- `if` statements
- `else` statements
- `else if` statements (or `elif` in some languages)
- `switch` statements (in languages like JavaScript and C#)
### Basic `if` Statement
The simplest form of a conditional is the `if` statement. It checks whether a
condition is met and executes the associated code if **true**.
#### Example in JavaScript:
```javascript
let temperature = 20;
if (temperature > 25) {
console.log("It's a hot day!");
}
```
Since `temperature` is **20**, and **not** greater than 25, the message won�t be
displayed.
### `if-else` Statement
An `if-else` statement provides an alternative action when the condition is
**false**.
#### Example in Python:
```python
age = 18
if age >= 21:
print("You can legally drink alcohol in the US.")
else:
print("You are not old enough.")
```
Since `age` is **18**, the program prints `"You are not old enough."`
### `else if` Statements
The `else if` structure lets you check multiple conditions in sequence.
#### Example in C#:
```csharp
int score = 75;
if (score >= 90) {
Console.WriteLine("Grade: A");
} else if (score >= 80) {
Console.WriteLine("Grade: B");
} else if (score >= 70) {
Console.WriteLine("Grade: C");
} else {
Console.WriteLine("Grade: F");
}
```
Since `score` is **75**, the program outputs `"Grade: C"`.
### `switch` Statements
In some languages, `switch` statements offer an alternative to multiple `else if`
conditions.
#### Example in JavaScript:
```javascript
let day = "Monday";
switch (day) {
case "Monday":
console.log("Start of the week!");
break;
case "Friday":
console.log("Almost the weekend!");
break;
default:
console.log("Just another day.");
}
```
Since `day` is `"Monday"`, it prints `"Start of the week!"`
### Why Are Conditionals Important?
- **Decision Making:** Programs can react dynamically to user input or data.
- **Efficiency:** Reduces repetitive code and enables cleaner logic.
- **Flexibility:** Allows different actions based on specific circumstances.