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 Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more