While Loop

Wed 04 July 2018, in category Loop

loop, while

A while loop is a similar construct to the for loop it allows you to iterate over a set of statements while the given expression is true. In our examples below, the while loop increments the i value as long as its less than 10.

Java

while(i < 10)
{
    System.out.println(i);
    i++;
}

C#

while(i < 10)
{
    Console.WriteLine(i);
    i++;
}

Python

while True:
    if i >= 10:
        break
    print(i)
    i=i+1

JavaScript

while (i < 10 ) {
    console.log(i);
    i++;
}

Go

for i < 10 {
    fmt.Println(i)
    i++
}