So far in this section I've seen 3 people struggling with their while loops. So what I'm going to do is break it down for you all to make it as easy as possible to understand.
Function of a while loop; A While loop allows you to execute a block of code a number of times without having to type it over and over.
Starting your While Loop
Before we can make the loop, we need something called a counter. What the counter will do is take your number you input for the counter "5" and print the line of text "5" times.
Now that we have our counter variable we can start giving it a value.
Now let me explain what each line of code does.
int counter =0; is saying the counter value = 0.
Next, you wanted to give your counter a number to go off of.
while(counter < 5){ is stating that as long as your variable counter is <5 it will print out "While loop tutorial" 5 times.
System.out.prinln("While loop tutorial"); is just printing out that line of code on to your screen.
And finally, counter++; This is stating that the counter will go up by 1 until it reaches 5.
Here is the full, working code.
I hope this helps people that are struggling with while loops. If you guys want more tutorials post on the thread below. Also, if you have any questions regarding your code feel free to pm me.
Function of a while loop; A While loop allows you to execute a block of code a number of times without having to type it over and over.
Starting your While Loop
Before we can make the loop, we need something called a counter. What the counter will do is take your number you input for the counter "5" and print the line of text "5" times.
Code
class Project1 {
public static void main(String args[]) {
int counter = 0;Now that we have our counter variable we can start giving it a value.
Code
while(counter < 5){
System.out.println("While loop tutorial");
counter++;Now let me explain what each line of code does.
int counter =0; is saying the counter value = 0.
Next, you wanted to give your counter a number to go off of.
while(counter < 5){ is stating that as long as your variable counter is <5 it will print out "While loop tutorial" 5 times.
System.out.prinln("While loop tutorial"); is just printing out that line of code on to your screen.
And finally, counter++; This is stating that the counter will go up by 1 until it reaches 5.
Here is the full, working code.
Code
class Project1 {
public static void main(String args[]) {
int counter = 0;
while(counter < 5){
System.out.println("While loop tutorial");
counter++;
}
}
}I hope this helps people that are struggling with while loops. If you guys want more tutorials post on the thread below. Also, if you have any questions regarding your code feel free to pm me.



![[Image: D12KBT6.png]](https://i.imgur.com/D12KBT6.png)
