Now let's talk about control structures logic, loops and all that kind of stuff. So the first kind of control structure we're going to deal with is an if statement. And every language has an if statement. We have a whole bunch of logical operators that we just got done talking about. Equals, the double equals is the question mark, triple equals is the same as and same type as, not equals, the knot, and then the and and the or. Double ampersand is and, and a double vertical bars or. And so triple equals and exclamation double equals, and curly braces are the way that we talk about to begin and end of the blocks that are affected by the if statement. So other than that we say if parentheses answer equals 42, this is kind of the question that we're going to ask and that's going to lead to a true or a false. If it's true of course, the first block is going to execute. And then there's an else and then if it's in that result is false the question is false then the else section is going to execute. And there it can be more than one line in here, I'm just showing one line to keep it small on the screen. So when this code all runs, it basically comes in answers 42, then this is true answers of 42 is true. It runs console.log Hello World, then skips the else clause and is all done. So the output of this is indeed Hello World. There's multi-way ifs and you can hang them together just like in with else ifs, just like in Python. And it does it in order if this is false, if the first if is false it checks the else if and as soon as that's true, it runs that block of code and then hops out to the end. It doesn't check all of the if questions simultaneously. And you can optionally have an else clause so that if none of the if else if clauses are true, then it just falls through and runs the code in the else block. You can have an indeterminate loop, a while loop that runs until something becomes true. It's a zero trip loop, which means that it's runs a minimum zero times, which means it's effectively functions the first time through like an if statement. So while fuel greater than 1, do this thing in the block is really like an if fuel greater than 1 do this block. Although in this case I built myself an infinite loop because fuel starts out at 10 and I say, while fuel feels greater than 1, console.logvroom, which means it's just going to do that forever. And that's because I didn't change the iteration variable in this case fuel, and usually we construct these in a way that they terminate eventually. And so I've done a much better job in the second one where I set fuel to 10 and I say well, if fuel is greater than one and inside the loop, I am console.logvroom. And then I subtract 1 and I go up and up and up and up, and then it's going to go and then its fuel will eventually get to 0 and then it will exit out the loop and finish. And so this here is an infinite loop and this is a finite loop. While loops are always a little tricky because you've got to construct the iteration variable or make sure you know how to get out of the loop. The for loop is a counted loop and it's going to run, and so there's three parts to it, and they're separated by semicolons. It looks really complex, but it's not. So you make an iteration variable, the first part up to the semicolon is the code that run before the loop starts. So I'm going to set this variable count equals 1. The second part is like a while and it's a top test0 trip loop, and as long as count remains less than or equal to 6, then the body Loop is going to execute. And then each time at the bottom of the loop we're going to add 1. So this is going to go, one, two, three four five six. When it's equal to 6 it's going to run the sixth time, but then it's going to come up and be 7, but then the loop is not going to run. And so that's what's called a counted loop or we have some variable that's just running through on a set of numbers. In Python we would use range to do this kind of a thing. Now like in Python, we've got the break statement, and the break statement just says I'm going to get out of this Loop. So if this line executes, it looks at the, if there's more than one loop, it's the innermost loop and it just basically escapes the loop and moves on to the line of code that follows the loop immediately. If it's done get out, don't execute another line it doesn't run that next, the rest of the iteration, it just skips out of the loop count completely. Continue is another very useful thing, you can basically say I want to give up on this iteration and go back up and do the next iteration. But the thing is this increment usually is this third part of the for loop. If you say continue that actually run, so it actually continue goes and does the ++. And then it does the check, and then neither continues to run back here or it jumps out if count is now greater than 10. And so continue works pretty much the same in loops, in JavaScript as it does in Python. So you can also loop through objects. And so here's an object that has three attributes golf, tennis and ping. And I can say for ball and balls and then that means that this iteration variable is going to walk through the keys or the attributes. So it's going to be golf, ping and tennis, and then I can use the lookup syntax to look up balls to golf, balls to tennis, and balls to Ping and then print all those things out. So that's what's called a definite loop, that's looping through an object that we're going to see. Now when you're drilling through an array which is a linear list, you actually use a counted loop not a definite loop. But objects which are like dictionaries which you like associative arrays will use definite loops to loop through them. So that is a quick romp through JavaScript not so much to get to the point where you can write a bunch of JavaScript. But so you can read it and then we get a syntax here hopefully you can fix it. [MUSIC]