While:
Another type of loop you can use in Java is called the while loop. While loops are a lot
easier to understand than for loops. Here's what they look like:
while ( condition ) {
}
So you start with the word "while" in lowercase. The condition you want to test for goes
between round brackets. A pair of curly brackets comes next, and the code you want to
execute goes between the curly brackets. As an example, here's a while loop that prints
out some text (Try the code out for yourself):
int loopVal = 0;
while ( loopVal < 5) {
System.out.println("Printing Some Text");
loopVal++;
}
Another type of loop you can use in Java is called the while loop. While loops are a lot
easier to understand than for loops. Here's what they look like:
while ( condition ) {
}
So you start with the word "while" in lowercase. The condition you want to test for goes
between round brackets. A pair of curly brackets comes next, and the code you want to
execute goes between the curly brackets. As an example, here's a while loop that prints
out some text (Try the code out for yourself):
int loopVal = 0;
while ( loopVal < 5) {
System.out.println("Printing Some Text");
loopVal++;
}
No comments:
Post a Comment