Java Basics

Java Basics 10: while loop

14 videos

80 minutes

Next Loop, which will be different for, is the while loop, this loop has the following structure, we While, forgiveness double vee, While. Here we set the condition, and within the braces put all that is going to have to run whenever this condition is met, we will make a example, so far we have seen that, have filled the matrix, have said that the first car has 10 seats, the second 20, the second 30 and that all

are filled halfway, so we will fill the first car, how do we do that? Let's say that the first car, here's 5, you see? That he It has first 10 and then has 5, here in May and we will fill until you have a 10, how do we do that? Let's ask this, let's say, while the number of passengers is less than the number of seats. How do we do that? The passenger is less than the number of seats, it is very

simple, put it, wagons, zero, 1; zero, one that is the number of passengers, is less than the number of seats, car that is, 'zero, zero' because only we will have the first wagon, wagons zero. While minor, which is what we do, we will increase you here, one by one, until this will be like a number of seats, so here we will say that cars, zero, 1 which is the number of passengers, increase one by one and

to make it look better, display it on screen, System.out.println, let's say show us how many passengers there are, here we 'passengers' ok! All right. Let's see how it would be now ... we are going to launch, and says it first has, when it comes has 5 passengers, which is what here has 5 passengers, actually we are going to put here, a message that we may see better here, 'at the beginning' and run again, has 5 passengers started at the beginning, and now with him

While Loop, is reviewing, and this condition is fulfilled because 5 is less than 10; which is the ability, as is true, comes by and increases by one, and shows, and it says here that has 6, returns again to While, the condition is satisfied because 6 is still less than 10, which is what's in here, in this data, so increases to 7, and so on up to 10 passengers, and 10 to, because while it is less, he was doing when he was 9

He has entered, because it was smaller and increased in 10, and check back to 10 less than 10, no! no longer comes in and does not. This is the while loop, ok! Is very simple, it's just like a, If, but here the condition and the keys are what is going to run constantly, we will see in the following video, how would be the Do While loop.

To find new courses, subscribe. There will be no spam, promised :)

About the Author

foto de jotajotavm
José Javier Villena

Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.