User Tools

Site Tools


code:loops

Table of Contents

Loops

Loops are very important for programming. Code in a loop is run over and over until a condition is met.

This page is incomplete.

Reason: array loops, while loops

For loops

JavaScript

loop.syjs
for (var x = 0; x < 5; x++) {
    print(x);
}

Python

loop.sypy
for x in range(0,5):
    print(x)

Java

loop.syjava
for (int x = 0; x < 5; x++) {
    print(x);
}

Output:

01234

This loop sets x to zero and runs the code inside until x is equal to or greater than 5. After each time the loop runs, it adds 1 to x (x++ is a shortcut for typing x = x + 1).

code/loops.txt · Last modified: 2019/04/16 02:40 (external edit)