Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

My Java Notes

Uploaded by

krcnair1939
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

My Java Notes

Uploaded by

krcnair1939
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java While Loop

int i = 0;

while (i < 5) {

System.out.println(i);

i++;

Do not forget to increase the variable used in the condition, otherwise the loop will never end!

Nested while Loop

class project1 {
public static void main(String a[])
{
int i =0;
while( i <=5)
{
System.out.println("hi");
int j=1;
while (j<3) {
System.out.println("good");
j++;

}
i++;
}
System.out.println(i);

}
}

The Do/While Loop


The do/while loop is a variant of the while loop. This loop will execute the code block once, before
checking if the condition is true, then it will repeat the loop as long as the condition is true.

int i = 0;
do {

System.out.println(i);

i++;

while (i < 5);

You might also like