Loops Advanced

2 minutes
Share the link to this page
Copied
  Completed
Learn about the advanced techniques in loops.

Transcript

Hello, in this JavaScript video, I am going to show you some more advanced techniques that you can use on loops. You can use them on any of the loops. I'll just keep importing using the for loop. Okay, so let's get rid of this. Let's get the source now. galore area pi signage error.

I will throw that out afterwards. let's reload, make sure we're getting what we want. from the previous video, back to zero. There we go. Okay. Pretty cool.

Okay, so there's two really cool statements that you can use with loops. There's the break statement and the continue statement. So the break statement, as soon as it hits that inside of a loop, anywhere where it's in an if statement in the loop or you know, some other curly braces, it was affected to break out of that loop. So let me show you really simple So I'm gonna say, oh, if it equals 50 we'll say, therefore save it, reload, we get your printed out. But if we look here, 02468, we get 48. When he hits 50, it goes inside here, and it'll break and that literally is canceled out to the for loop.

Any code afterwards will still continue running. And the other thing that I want to show you is the continuous thing. for proper continue. What this does is skips this particular iteration of the for loop or the loop I should say. And then he continues with any more iterations they have left. If I reload.

As you can see, we get zero and he finishes at 100 before you go up and get to where 50 We should be, we are 4648. But then the 52 because when I is 50, it continues. So what that does is skips any code after that goes back to the start of the loop and just continues with the next iteration of the loop. And that's a really cool advanced techniques that you can use with loops. These are pretty universal in most languages. And in some programming languages, the code is exactly the same.

One of the things I love about JavaScript not only easy, so easy to set up and actually use a lot of the syntax is almost identical to many other popular languages, like c++, C, PHP can be built. On top of that the c++ sort of syntax and foundation. Thanks for watching. If you have any questions, feel free to pop me a message and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.