The while loop executes a set of statements in it's body until something in it's parameter field changes to something else other then what is given.
Code:
while (variableExample) {
sendMessage("LOL");
}
This basically means while the variable, variableExample is of condition true, it'll send a message of 'LOL' until the variable, variableExample, is of false condition. Sounds simple, and it is; however, if you couldn't comprehend that - perhaps try and understand this:
Code:
while (counter < 11) {
variable++;
}
This is another example of using the while loop. If the variable, counter, isn't equal to 10, then it'll continue to count up until it reaches that given number. The following code snippet located below is an example of a working class that uses the while loop. Sure, the class itself isn't the best; however it just shows an example so don't bicker about that.
Code:
public class Example {
public static int counter = 0;
public static void main(String args[]) {
while (counter < 5) {
counter++;
System.out.println("Variable 'counter' is equal to: "+counter+"");
}
if (counter == 4) {
System.out.println("The variable 'counter' is now equal to four!");
}
}
}
Hope you've learned something throughout this tutorial, good luck in the future!