Menu

1 / 2

Looping Statements in Java

DEV Community: java·Rakshambika·8 days ago
#4pzUCjfA
#devtojava#devto#dev#loop#condition
Long article (634 words) — no AI summary yet.
Reading 0:00
15s threshold

What is Looping Statement ?

Looping statement is used to execute the block of code repeatedly as long as the specified condition is true.

Looping is used to reduce the number of lines.

Instead of writing the same code multiple times , we can use loops to perform that task efficiently.

Types of Looping Statement:

While Loop

Do While Loop

For Loop

While Loop:

While loop is used to execute the block of code until the specified condition is true.

While is used when we don't know the number of iterations of loop.

while loop is an entry-controlled loop , because it checks the condition before executing the block of code.

Syntax:

while ( condition ) { // block of code }

Enter fullscreen mode

Exit fullscreen mode

Example:

public class While_Loop {

public static void main ( String [ ] args ) {

int count = 1 ; while ( count <= 5 ) { System . out .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.