02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

The meaning of Curly Brackets

This starts up our first session with Carole talking about loops the biggest issue that we encounter first is the actual meaning of the curly Brackets. How does this relate to score?

Video Transcript

00:00Welcome to the developer basics. We're having a small session with Carol. We called it looping where Carol just finished watching the first loops video.
00:12We wanted to make sure that everything is clear and if there's any issue we're going to try to figure out how to solve it together.
00:18So Carol, it's all yours. From now on, let me start asking, first of all, you just watched a whole hour of loops and really the first fundamental question is what are loops?
00:30Well, I think you said it right besides one piece and maybe it's important to clarify that one is that functions are very different than variables and objects.
01:06And the reason is because a function or sorry, well, even it's different than functions because when we're talking about loops, loops are different than functions and variables and all this stuff that we've learned about so far because loops don't store anything.
01:22You can't save a loop. A loop is just a command to tell the operating system do this X amount of times.
01:29So even if I just write here a really quick loop, let me just go to actions. I'll just add here a for bar typing with one hand is a little bit hard.
01:43Let me just put the telephone down for a second. All right, so for bar i equals zero i is smaller than 10 i plus plus.
01:54Really, the only piece of information, only stored information that we have is this i value. It's that integer. That's our variable. But the for is just a command. It's a command that says do this 10 times. Whatever's inside here, it could be anything.
02:06Now, it's important to know that you have your curly braces and that's why you're confusing it. And it's only because when you have a function and it's good that you're pointing this out.
02:15We have our function and we open and we close a curly bracket and we've done that a few times already. And all the times that we've done it so far, almost all the times we've done it so far, it was some sort of object.
02:29But opening and closing brackets is not only always a definition of of a thing. It's more of a definition of a zone of this is the area, the workable area.
02:38Now, with that said, it's true and that might be a little bit confusing because you could also create a new object and just set it up by opening and closing a curly bracket.
02:47Now, opening and closing a curly bracket is definitely does create a new object when you're only putting it that and there's nothing before it and there's nothing after it.
02:55But on the other hand, whenever you're creating a function, well, a function is also a thing, right? It could be it's something tangible because they're saying that's inside of it.
03:03But in the case of a for loop, it's not something tangible. All we're saying is that everything inside of here is part of the loop. Just repeat this, go to line three. And then when you're done, go back to line one, go back to line one, go back and go back until you're done with the loop.
03:16And when you're done, then move on to line four. Now, we've seen this again, we've seen this also in another place where if we had if statements, for example, if a is bigger than B, then we opened a curly bracket and close the curly bracket.
03:28With that said, the if statement is not a thing either. The if statement is just a command and operation that says, if this is true, then we're going to do that those commands that are inside.
03:37So if statements and for loops are quite similar in that that they're zoning, their area is not really, it's not really an object. It's not really something that you could store later and use it for other cases.
03:48If you wanted to use it, if again, what would you have to do, Carol? Well, but you can't do what? Let me ask you. Okay, let me rephrase the question.
04:02So I'm going to rephrase the question and say, could I say this equals is that is that valid? Well, also, because the I can declare one is this is not really valid, because you can't take an if statement and put it into an if you can't put it into a variable, because it's not a thing.
04:34It's more of a command. It's more like saying, I'm trying to try to find an example in the real world.
04:42An example in the real world will be like you have someone standing in the door, and he tells you, you could come in, you could you can't come in, right? You can't take that scenario, wrap it up in a in a something, and then reuse it in other places, right?
04:56That doesn't even make sense. On the other hand, if you say, like, here, I have an apple, I can take that apple, put it in my pocket and use that apple in another, another place.
05:05If statement really isn't something tangible, it's something it's a more of a theoretical if something happens, then do this. If something else happens, then do that. So I can't take an if statement and just put it directly into a variable because it's not a something.
05:18It's not saying tangible. And the same is true for a for statement. A for statement is not, it's not something tangible. It's not a thing. It's just a command that says, for this, as long as this is true, as long as this is happening, then just repeat this action over and over.
05:33Now, with that said, if I, exactly, it's like a, yeah, exactly. It's like an office or a commander, something that's telling the program, like you said, to do something.
05:50Now, if I needed this if statement, and I needed to use it a few times, then I would have to, or I could put it inside of a loop. I live next to a fire department. So like every 30 minutes, this happens.
06:04So I could put it or in a for loop if I wanted this if to happen 10 times, right? Or if I wanted to, I could have taken that for that if statement, just put it in a function, right? And then I could call it whenever I need it.
06:15So really, this is a function is a thing. A function is much is very much like a bucket. So I could put things into that bucket if I want to put commands into the bucket.
06:25Okay, that makes sense.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!