0% found this document useful (0 votes)
44 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)
44 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy