# Learn Swift for Beginners 2026 - Lesson 8 - Logical Operators

## Метаданные

- **Канал:** CodeWithChris
- **YouTube:** https://www.youtube.com/watch?v=YDtVZnC_2zU
- **Дата:** 01.05.2026
- **Длительность:** 7:44
- **Просмотры:** 413

## Описание

Learn how to use logical operators in Swift, including AND (&&), OR (||), and NOT (!), to write more powerful conditional statements in your iOS apps.

Resources:
📚 Full guide: 
https://codewithchris.com/learn-swift?utm_source=youtube&utm_medium=video&utm_campaign=learn_swift_lesson_8

In this lesson, you'll learn how to chain multiple conditions into a single if statement, use parentheses to group logic, and combine operators to handle real-world scenarios like a theme park ride checker.

What you'll learn:

- AND (&&): both conditions must be true
- OR (||): either condition can be true
- NOT (!): flips a boolean from true to false (or vice versa)
- How to combine multiple logical operators with parentheses
- How to write an if/else statement with complex conditions

Timestamps:
0:00 Intro to Logical Operators
0:20 Chaining Multiple Conditions
1:26 OR Operator Example
2:14 NOT Operator (!)
2:35 Flipping True/False with !
2:55 AND (&&), OR (||), NOT (!) Overview
3:01 How to Type the Pipe Character
3:17 Combining Multiple Operators
3:47 Complex Example with Parentheses
5:06 Theme Park Challenge
5:39 Challenge Solution
7:29 AI Side Panel Tips

This is Lesson 8 of the Learn Swift series. If you're just getting started, go back to the beginning of the playlist to follow along from scratch.

LearnSwift #SwiftProgramming #iOSDevelopment

## Содержание

### [0:00](https://www.youtube.com/watch?v=YDtVZnC_2zU) Intro to Logical Operators

All right, we're making really good progress into chapter two and we are looking at logical operators which are going to make lessons one and two in stage two much more powerful. So we're building upon these lessons as we move. Logical operators, what are they?

### [0:20](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=20s) Chaining Multiple Conditions

Essentially, it allows you to chain together multiple conditions into a single if statement. So Let's take a look at this example. So we have age is 20, has subscription is true, and is birthday is false. If we want to execute some code only if multiple conditions are true we can use an and. So if age is over or equal to 18 and has a subscription is true both of them need to be true. Then the whole thing is true. And we print out enjoy the content. So you see that down here. Or will evaluate to true if either this or this is true. Only one of them has to be true and then the whole thing is evaluated as true and it will print this out.

### [1:26](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=86s) OR Operator Example

So here, since is birthday is false this is false, but this is true. So it still prints out can you can get a bonus reward. Now this exclamation mark here is the inverse or the opposite. It flips it around. So this is saying if is birthday is not true birthday is currently set to false. But this flips it to true. So now it evaluates to no birthday bonus today. See it evaluates to true. Even though this is false because this is the inverse of that. So just to

### [2:14](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=134s) NOT Operator (!)

hammer that home, if I change this to true this exclamation mark changes that to false. Right? It just flips it from true to false or from false to true. And so now this does not get printed because this whole this evaluates to false.

### [2:35](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=155s) Flipping True/False with !

Right? So let's take a look. Why is this helpful for us? And here it is again. So double ampersand is and, double pipe is or, and exclamation is not. Now pipe is not the same thing as this is not an L. Okay? This is when you hold down shift and you hit

### [2:55](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=175s) AND (&&), OR (||), NOT (!) Overview

backslash. That's the key you get. So backslash, right? Hold shift and you get

### [3:01](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=181s) How to Type the Pipe Character

pipes. You need double pipe for an or. And so for me on this keyboard on this US layout that key is to the right of the plus equals the plus equal key.

### [3:17](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=197s) Combining Multiple Operators

Okay, so for an and remember both conditions need to be true. For the or either can be true. And exclamation is not. Now this is where things get confusing because you can use parentheses or rounded brackets to group things together and you can chain together multiple ands and multiple ors. So let's take a look at this example right here.

### [3:47](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=227s) Complex Example with Parentheses

This is trying to combine everything together. Okay? So is weekend is true, has chores is false, and friends available is true. So this is saying if it is the weekend and so it has to be true, right? And this is true either friends available needs to be true or has chores the inverse of that has to be true. So has chores is currently false, right? Exclamation mark in front of that flips that to true. So this is true which makes the whole thing true and this is also true. So the and statement is satisfied. So this is going to print out. Friends available is also true. So even if this was false this would have been enough because it's an or. Right? Either this is true or this is true. So you can chain together multiple comparison op- or logical operators like that. Let's take a look at this challenge. A theme park ride has two rules. The

### [5:06](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=306s) Theme Park Challenge

riders must be at least 120 cm tall and must not have a fear of heights. Create variables for height cm and fear of heights. This is an integer and fear of heights is a bool. Write an if else statement that prints enjoy the ride when both requirements are met. If not, print a specific message explaining which requirement wasn't met. So let's go ahead. I'll pause the video if you want to try this challenge. I always recommend that.

### [5:39](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=339s) Challenge Solution

False and let height cm equals 180. If height cm is greater than or equal to 180 and not fear of heights then print enjoy the ride. Is that correct? Oh, sorry. 120. Must be at least 120 and must not have a fear of heights. So that's it's 120. So in this case it would print let's go. Okay? Else if fear of heights then print maybe try the rides in the kids zone. Else wait until you get a bit taller. So if I do have a fear of heights then it's going to hit this one. Oh. S- Okay. Maybe try the rides in the kids zone. Or if this was false and I'm not tall enough it would say wait until you get a bit taller. That's how you do that challenge. And as usual, to go deeper with AI, make sure you use the AI side panel here.

### [7:29](https://www.youtube.com/watch?v=YDtVZnC_2zU&t=449s) AI Side Panel Tips

These prompts will challenge your thinking, it will expand on the concept a little bit more, and you have the option of getting some more examples to practice with. All right, I'll see you in the next lesson.

---
*Источник: https://ekstraktznaniy.ru/video/49665*