Choose Your Language

Thursday 4 April 2013

Looping Control structure

Control structure includes the looping control structure and conditional or branching control structure. 
In a looping control structure, series of statements are repeated.

looping control structure

for loop
Syntax:
for(intial value;condition;increment or decrement){
Statements;


Example:
Class ForLoop{
public static void main(String a[]){
for(int i=0;i<3;i++){
System.out.println(i);


output:
0
1
2
 
while loop
Syntax:
while (condition){
Statements;
}

Example:
Class While Loop{
public static void main(String a[]){
int i=0;
while (i<3){
System.out.println(i);
i++;


output:
0
1
2


do..while loop 
Syntax:
do{
Statements;

while(condition);

Example

Class DoWhileLoop{
public static void main(String a[]){
int i=0;
do{
 System.out.println(i); 
i++
}
while (i<3)

output:
0
1
2

No comments:

Post a Comment