> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/NormandoRamirezDelgado/6C-Febrero-2026/llms.txt
> Use this file to discover all available pages before exploring further.

# Logical Operators

> Learn how to combine and manipulate boolean values using logical operators in Dart

## Overview

Logical operators are used to combine or invert boolean values. They are essential for creating complex conditions in your programs.

## Logical Operators Table

| Operator | Name | Description                              | Example                   |                                                |        |   |                |
| -------- | ---- | ---------------------------------------- | ------------------------- | ---------------------------------------------- | ------ | - | -------------- |
| `&&`     | AND  | Returns `true` if both operands are true | `true && false` → `false` |                                                |        |   |                |
| \`       |      | \`                                       | OR                        | Returns `true` if at least one operand is true | \`true |   | false`→`true\` |
| `!`      | NOT  | Inverts the boolean value                | `!true` → `false`         |                                                |        |   |                |

## Basic Example

Here's a complete example demonstrating logical operators:

```dart theme={null}
void main() {
  bool esEstudiante = true;
  bool tieneTitulo = false;
  int valor = 28;

  print(valor == 18 || tieneTitulo);
  print(esEstudiante && tieneTitulo);  // AND: false
  //print(esEstudiante || tieneTitulo);  // OR: true
  print(!esEstudiante);                // NOT: false

  /*
  Tabla de verdad AND:
  true  && true   = true
  true  && false  = false
  false && true   = false
  false && false  = false
  */
}
```

**Output:**

```
false
false
false
```

## AND Operator (`&&`)

The AND operator returns `true` only when **both** conditions are true.

### Truth Table for AND

| Left    | Right   | Result  |
| ------- | ------- | ------- |
| `true`  | `true`  | `true`  |
| `true`  | `false` | `false` |
| `false` | `true`  | `false` |
| `false` | `false` | `false` |

### Example

```dart theme={null}
bool hasLicense = true;
bool hasInsurance = true;
bool canDrive = hasLicense && hasInsurance;
print(canDrive);  // Output: true
```

<Note>
  The AND operator uses "short-circuit" evaluation: if the left operand is `false`, the right operand is not evaluated because the result will always be `false`.
</Note>

## OR Operator (`||`)

The OR operator returns `true` when **at least one** condition is true.

### Truth Table for OR

| Left    | Right   | Result  |
| ------- | ------- | ------- |
| `true`  | `true`  | `true`  |
| `true`  | `false` | `true`  |
| `false` | `true`  | `true`  |
| `false` | `false` | `false` |

### Example

```dart theme={null}
bool isWeekend = false;
bool isHoliday = true;
bool canRelax = isWeekend || isHoliday;
print(canRelax);  // Output: true
```

<Note>
  The OR operator also uses "short-circuit" evaluation: if the left operand is `true`, the right operand is not evaluated because the result will always be `true`.
</Note>

## NOT Operator (`!`)

The NOT operator inverts a boolean value.

### Truth Table for NOT

| Value   | Result  |
| ------- | ------- |
| `true`  | `false` |
| `false` | `true`  |

### Example

```dart theme={null}
bool isLoggedIn = true;
bool isGuest = !isLoggedIn;
print(isGuest);  // Output: false
```

<Tip>
  The NOT operator is useful for checking the opposite of a condition. For example, `!isEmpty` is more readable than `isEmpty == false`.
</Tip>

## Combining Logical Operators

You can combine multiple logical operators to create complex conditions:

```dart theme={null}
int age = 25;
bool hasTicket = true;
bool isStudent = false;

// Must be 18 or older AND have a ticket OR be a student
bool canEnter = (age >= 18 && hasTicket) || isStudent;
print(canEnter);  // Output: true
```

## Practical Examples

### Access Control

```dart theme={null}
bool isAdmin = false;
bool isOwner = true;
bool canDelete = isAdmin || isOwner;
print(canDelete);  // Output: true
```

### Form Validation

```dart theme={null}
String username = "john";
String password = "pass1234";

bool validUsername = username.length >= 3;
bool validPassword = password.length >= 8;
bool canSubmit = validUsername && validPassword;

print(canSubmit);  // Output: true
```

### Eligibility Check

```dart theme={null}
int age = 16;
bool hasParentalConsent = true;

bool canParticipate = age >= 18 || (age >= 13 && hasParentalConsent);
print(canParticipate);  // Output: true
```

### Inverted Conditions

```dart theme={null}
bool isProcessing = false;
bool canStart = !isProcessing;
print(canStart);  // Output: true
```
