90 for loop JS - JavaScript Tutorial 2018

preview_player
Показать описание
The Full #Javascript #tutorial for #beginners :

Learn HTML, CSS and JavaScript

JavaScript Tutorial 2018

90 for loop JS - JavaScript for Beginners.

This is a Javascript tutorial from scratch for any beginner. Use the above link to watch the full JS video tutorial..

In the last part, we did the ‘while’ loop and the ‘do-while’ loop and we saw the difference between the two.

So in this section, let’s move on to ‘for’ loop.

And a ‘for’ loop, the way it works is that you will have for, everything will be put inside here, in most cases that is.

So you’ll have the initialization.

So if you think in terms of our last example which was printing 1, 2, 3, 4, 5, our initialization was ‘var x=1’.

And then the condition, this is what is checked.

If it’s true, this will get run.

If not, it won’t get run.

So our condition in the last one was ‘x less or equal to 5’.

So if you don’t understand these operators, I do implore you to go and watch my Intro to programming course because I covered all of this.

So once you watch that, all this will be a piece of cake to you.

After the condition, we have the update.

Now the update is either the increment or the decrement.

In our case, in the last example we used an increment which was x++.

It can be anything.

It can even be x=x+10.

Maybe you want to move from 90, 100, 110, you can do something like this.

So it can be anything.

It doesn’t have to be x++.

It depends on what you want to do.

If you want to print maybe 1, [xx xx] example that I think we, we should do now whereby we print, we print ‘x’ and then we print 10, 20 and we’re going to use this so that you, you can say that you don’t necessarily have to use x++.

So how this one works is it will check the initialization which can be done within the 'for' loop or it can be done above the 'for' loop.

And then it will check the condition.

Once it checks that the initialization has been done, it will come to the condition, next.

Now here in the condition, we check is this true? If the condition is true, it will go here.

If the condition is true, it will do whatever is here.

And then, once it does whatever is here, maybe to print something for us.

And then, once that has been done, it will come back like this and it will update.

Now, it will update the value and then go into the condition.

If the condition is true, it will come back and print whatever we have here.

And once that one is done, it will again come back and update the value.

And if the update comes back to the condition, maybe this time around it is false.

If it is false, this will go all the way out of the loop.

It will take us out of the loop.

So that’s how it works.

Comes that way, runs, then goes updates condition.

As long as this condition is true, what happens is, it will just continue going like that as long as the condition is true.

The moment it becomes false, it will come from the condition and take us outside of this loop.

So it runs until the condition becomes false.

So in the next video, we’re going to do an example just to see how it works.

And in this case, we are going to do an x+10 and not an x++ so that we can see that we don’t have to use x++.

You can use whichever incremental value or decremental value you want to use.

So I’ll see you in the next video when we work on an example.

.
GET SOCIAL WITH ME:
Рекомендации по теме
welcome to shbcf.ru