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

Looping Statement

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

Looping Statement

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

2)Iterative Statement.

(Looping Statement)

1)for loop
2)while loop
3)do while loop
4)forEach loop

Example 1: without loping statement

package loopingMakingStatements;

public class ForDemo {

public static void main(String[] args) {

System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");

System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");

System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");

System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
System.out.println("Welcome to BikkadIT");
}
}

Example 2: With looping statement

package loopingMakingStatements;

public class ForDemo {

public static void main(String[] args) {

for(int i=0;i<20;i++) {
System.out.println("Welcome to BikkadIT");
}
}
}
1)for loop:

Syntax : for(initialization ; condition ;inc/dec){

---------------
}

Example :

package loopingMakingStatements;

public class ForDemo {

public static void main(String[] args) {

for (int i = 0; i < 3; i++) {


System.out.println("Welcome to BikkadIT");
}
}
}

Example :

package loopingMakingStatements;

public class ForDemo {

public static void main(String[] args) {

for (int i = 1; i <= 10; i++) {


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

Example :

package loopingMakingStatements;

public class ForDemo {

public static void main(String[] args) {

for (int i = 10; i>=1 ; i--) {


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

2)while loop :

initialization;
while(condition){
inc/dec;
}

Example :

package loopingMakingStatements;

public class WhileDemo {

public static void main(String[] args) {

int i = 1;

while (i <= 5) {
System.out.println("Welcome to BikkadIT");
i++;
}
}
}

Example :

package loopingMakingStatements;

public class WhileDemo {

public static void main(String[] args) {

int i = 1;

while (i <= 10) {


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

Example :

package loopingMakingStatements;

public class WhileDemo {

public static void main(String[] args) {

int i = 10;

while (i >= 1) {
System.out.println(i);
i--;
}
}
}

You might also like