DEV Community

SATHISH BALAJI
SATHISH BALAJI

Posted on

While Loop

Java while loop

The while loop is also used to iterate over the number of statements multiple times. However, if we don't know the number of iterations in advance, it is recommended to use a while loop. Unlike for loop, the initialization and increment/decrement doesn't take place inside the loop statement in while loop.

It is also known as the entry-controlled loop since the condition is checked at the start of the loop. If the condition is true, then the loop body will be executed; otherwise, the statements after the loop will be executed.

Image description

Calculation .java

    public class Calculation {    
    public static void main(String[] args) {    
    // TODO Auto-generated method stub    
    int i = 0;    
    System.out.println("Printing the list of first 10 even numbers \n");    
    while(i<=10) {    
    System.out.println(i);    
    i = i + 2;    
    }    
    }    
    }    
Enter fullscreen mode Exit fullscreen mode

Output:

Printing the list of first 10 even numbers 

0
2
4
6
8
10
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Diagram Like A Pro

Bring your cloud architecture to life with expert tips from AWS and Datadog. In this ebook, AWS Solutions Architects Jason Mimick and James Wenzel reveal pro strategies for building clear, compelling diagrams that make an impact.

Get the Guide

Top comments (0)

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay