Why use a while loop? Well, if you want to do something many times over then a while loop is probably what you are looking for. Heres a generic example of a while loop.
Well that doesnt make much sense on its own. Heres a slightly more clear version of the same sort of thing.
This makes a little more sense. This will carry on executing whatever you put inside the body of the loop (Between the and ) until loopyVariable is less than 5. There are a couple of nice new things you need to know about. Firstly, the < sign means less than. > is greater than and you may also need to know >= (Greater than or equal to) and <= (Less than or equal to). Secondly, the loopyVariable++; bit is new. This just means add one to the current value of loopyVariable. Its the same thing as writing loopyVariable = loopyVariable + 1; only in a shorthand form. Finally, you must note that the loopyVariable is incremented! If this didnt happen then the loop would carry on forever. Thats a BAD THING and you should not let it happen. Its also one of the reasons for loops are better than while loops for this type of thing (And we will do for loops after while loops.).
Going back to the example of the car with passengers, if we wanted to fill the car with people called bob then maybe this is how we would do it using the while loop.
This is how the computer would execute it (Assuming i is 0 and car is an array of Strings with length 5)
i is 0 which is less than 5, store "bob" into car[0], increase i from 0 to 1.
i is 1 which is less than 5, store "bob" into car[1], increase i from 1 to 2.
i is 2 which is less than 5, store "bob" into car[2], increase i from 2 to 3.
i is 3 which is less than 5, store "bob" into car[3], increase i from 3 to 4.
i is 4 which is less than 5, store "bob" into car[4], increase i from 4 to 5.
i is 5 which is not less than 5, skip over the stuff inside the while
So by the end of that while loop the array of Strings called car would be full up with people called "bob". However, a for loop is much nicer for this kind of thing...