Javatpoint Logo
Javatpoint Logo

Kotlin while Loop

The while loop is used to iterate a part of program several time. Loop executed the block of code until the condition has true. Kotlin while loop is similar to Java while loop.

Syntax

Example of while Loop

Let's see a simple example of while loop printing value from 1 to 5.

Output:

1
2
3
4
5

Kotlin Infinite while Loop

The while loop executes a block of code to infinite times, if while condition remain true.

For example:

Output:

infinite loop
infinite loop
infinite loop
.
.
.
.
infinite loop
infinite loop

 
infinite loop
infinite loop
infinite loop
infinite loop





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA