0% found this document useful (0 votes)
40 views

Java Loops

Uploaded by

vyasflame1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Java Loops

Uploaded by

vyasflame1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Loops

1) While loop
2) do while loop
3) for loop
4) for each loop

1) The basic format ofwhile loop statement is:


Syntax:
Int i=1;
While (condition)
{
statement(s);
Incrementation;
}

Example of a Java Program to Demonstrate while loop


public class Sample
{
public static void main(String args[]) {
/* local variable Initialization */
int n = 1, times = 5;

/* while loops execution */


while (n <= times) {
System.out.println("Java while loops:" + n);
n++;
}
}
}

2) The basic format of do while loop statement is:


Syntax:
Int i=1;
do
{
statement(s);
i++;
}while( condition );

Example of a Java Program to Demonstrate do whileloop


public class Sample {
public static void main(String args[]) {
/* local variable Initialization */
int n = 1, times = 0;

/* do-while loops execution */


do {
System.out.println("Java do while loops:" + n);
n++;
} while (n <= times)
}
}
3) The basic format of for loop statement is:
Syntax:
for( initialization; condition; increment /decrement)
{
statement(s);
}
Example of a Java Program to Demonstrate for loop
public class Sample {
public static void main(String args[]) {
/* local variable Initialization */
int n = 1, times = 5;

/* for loops execution */


for (n = 1; n <= times; n = n + 1) {
System.out.println("Java for loops:" + n);
}
}
}

For(int i : max)

---------

You might also like