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

Automation Notes (16.03.2022)

The document discusses while loops in Java, including the syntax and examples of using while loops to print numbers in sequences like counting up or down. It provides 5 code examples of using while loops for different counting and printing tasks.

Uploaded by

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

Automation Notes (16.03.2022)

The document discusses while loops in Java, including the syntax and examples of using while loops to print numbers in sequences like counting up or down. It provides 5 code examples of using while loops for different counting and printing tasks.

Uploaded by

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

While

Loop:
while loop is preferred to use, If the number of iteration is not fixed. It is pre-test loop
it is also called as entry control loop

Syntax :
 while(condition){ 

//code to be executed 

}


Program:
public class WhileLoop1 {

public static void main(String[] args) {

//1 2 3 4 5

// for(int i=1;i<6;i++)
// {
// System.out.println(i);
// }

int i=1; //i=6
while(i<6) //6<6 x
{
System.out.println(i); //1 2 3 4 5
i++;
}

}

}


Program:
public class WhileLoop2 {

public static void main(String[] args) {

//2 4 6 8 10 Even number upto 50

int i=2;
while(i<=50)
{
System.out.print(i + " ");
i=i+2;
}
}
}



Program:
public class WhileLoop3 {

public static void main(String[] args) {

//1 8 27 64 125

int i=1; //i=6
while(i<=5) //6<=5
{
System.out.println(i*i*i); //1 8 27 64 125
i++;
}

}

}

Program:
public class WhileLoop4 {

public static void main(String[] args) {
//20 19 18 .........1

int i=20;
while(i>=1) //20>=1
{
System.out.print(i + " ");
i--;
}
}
}

Program:
public class WhileLoop5 {

public static void main(String[] args) {

//19 17 15.......1

int i=19;
while(i>=1)
{
System.out.print(i + " ");
i=i-2;
}
}
}

You might also like