DEV Community

hema latha
hema latha

Posted on

control flow statement?

The while loop loops through a block of code as long as a specified condition is true
while (condition) {
// code block to be executed
}
In the example below, the code in the loop will run, over and over again, as long as a variable (i) is less than 5:

ex--
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}

key examples include "if-else" for conditional checks, "for" and "while" for looping, and "switch" for multiple condition checks.

Image description

task 1
package day1;

public class While_basic {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int count = 1;
    while(count<=5)

    {
    System.out.println(count);
    count=count+1;
    }
}
Enter fullscreen mode Exit fullscreen mode

}

out put --
1
2
3
4
5

task 2

public static void main(String[] args) {
    int count = 1;
    while(count<=10)
    {
    System.out.println(count);
    count= count+2;
    }
Enter fullscreen mode Exit fullscreen mode

out put -
1
3
5
7
9

task 3
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
while(count<=10)
{
System.out.println(count);
count= count+2;

out put --
0
2
4
6
8
10

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more