For Loop

Wed 04 July 2018, in category Loop

for, loop

The ol' reliable for loop. One of the first looping constructs taught in most programming languages, which enables you to execute a set of statements until the for expression evaluates to false.
Here are a few examples from various languages, all of which print 0 through 9 out to the console.

Java

for (int i=0; i<10; i++)
{
     System.out.println(i);
}

C#

for (int i=0; i<10; i++)
{
    Console.WriteLine(i);
}

Python

for x in range(0,10):
    print(x)

JavaScript

for (i=0; i<10; i++){
    console.log(i);
}

Go

for i:=0; i<10; i++ {
    fmt.Println(i)
}