Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Yes, in programming languages we are really picky about the symbols we use and about what we call them. So just to be very specific, when I say parentheses, I mean these; when I say brackets and I usually say square brackets, I mean these guys; and when I say braces, and I'll usually say curly braces, I mean these. Now, they serve similar purposes, to mark where something starts and where it finishes, but they are not interchangeable. Now all of these are always found in pairs. If you have an opening one, you will need a closing one.
We will come back and talk about equality again, but realize for now that if, in a condition, if you're asking if something is equal to something else, you will never use a single equal sign. As we saw with variables, a single equal sign is an assignment. It's a command. It sets a value, not checks a value. So we can use double equals or right now triple equals will do the same thing. Again, we'll come back to this one. And if I want to check that a variable is not equal another value, it's the exclamation mark and equal sign, in this case checking that the variable d is not equal to 100.
If that's true, we will execute our code. When you have several statements surrounded by these curly braces, this is what's referred to as a code block, and this is all the curly braces do. They group a section of code together. They don't have any other meaning than that. And as you will see, these blocks can be nested the same way, say, in HTML you can nest divs inside other divs. Now a quick word about curly braces. When reading other people's code, you're likely to see them occur in a couple of different styles.
So if this code is executed when the condition is true, well, what happens if it isn't? If we just leave it like this, nothing. It would skip over the if and begin on the next line. But if you wanted something else to happen, you can follow the if with an else statement and in this case have another code block that runs different code. If the first condition is true, we run the code in the first block; otherwise, we run the code in the second block. And you can even nest them inside each other and check a different condition. But don't nest too deep.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97479 Viewers
61 Video lessons · 84712 Viewers
71 Video lessons · 68907 Viewers
56 Video lessons · 101355 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.