• Loops

    A loop in programming is like running around a track. When you start running, you keep going until you have gone around the track once. In programming, a loop is when you tell the computer to do the same thing over and over again until it has done what you told it to do. For example, if you want your computer to count from 1 to 10, it will create a loop that says "count 1, count 2, count 3" all the way up to 10.

      • For Loops

      • Javascript

        Example of for loop in javascript.
        for (var key = 1; key < 4; key++) {
        	console.log(key); // 1, 2, 3
        }
      • Dart

        Example of for loop in dart.
        void main() {
          for (var key = 1; key < 4; key++) {
        	print(key); // 1, 2, 3
          }
        }
        
      • D

        Example of for loop in d.
        import std.stdio : writeln;
        
        void main()
        {
        	for (int key = 1; key < 4; key++) {
        		writeln(key); // 1, 2, 3
        	}
        }
        
      • Php

        Example of for loop in php.
        <?php
        for ($key = 1; $key < 4; $key++) {
        	print($key); // 1, 2, 3
        }
        
      • Python

        Example of for loop in python.
        for key in range(1, 4):
          print(key) # 1, 2, 3
      • Go

        Example of for loop in go.
        package main
        
        import "fmt"
        
        func main() {
        	for key := 1; key < 4; key++ {
        		fmt.Println(key)
        	}
        }
        
      • For ...in Loops

      • Javascript

        Example of for-in loop in javascript.
        var fruits = {a: 'apple', b: 'banana', c: 'cherry'};
        
        for (var key in fruits) {
        	console.log(`${key}: ${fruits[key]}`); // a: apple etc.
        }
      • Dart

        Example of for-in loop in dart.
        void main() {
          var fruits = {'a': 'apple', 'b': 'banana', 'c': 'cherry'};
        
          for (var key in fruits.keys) {
        	print('${key}: ${fruits[key]}'); // a: apple etc.
          }
        }
        
      • D

        Example of for-in loop in d.
        import std.stdio : writeln;
        import std.string;
        import std.array;
        
        void main()
        {
        	string[string] fruits = ["a": "apple", "b": "banana", "c": "cherry"];
        
        	foreach (key, value; fruits) {
        		writeln(key, ": ", value); // c: cherry etc. (does not preserve order)
        	}
        }
        
      • Php

        Example of for-in loop in php.
        <?php
        $fruits = ['a' => 'apple', 'b' => 'banana', 'c' => 'cherry'];
        
        foreach ($fruits as $key => $value) {
        	print("$key: $value"); // a: apple etc.
        }
      • Python

        Example of for-in loop in python.
        fruits = {'a': 'apple', 'b': 'banana', 'c': 'cherry'}
        
        for key, value in fruits.items():
          print(f'{key}: {value}') # a: apple etc.
      • Go

        Example of for-in loop in go.
        package main
        
        import "fmt"
        
        func main() {
        	var fruits = map[string]string{"a": "apple", "b": "banana", "c": "cherry"}
        
        	for key, value := range fruits {
        		fmt.Println(key + ": " + value) // a: apple etc.
        	}
        }
        
      • While Loops

      • Javascript

        Example of while loop in javascript.
        var times = 1;
        
        while(times <= 5){
        	console.log(`Looped ${times}`); // Looped 1 etc.
        	times += 1;
        }
      • Dart

        Example of while loop in dart.
        void main() {
          var times = 1;
        
          while (times <= 5) {
        	print('Looped ${times}'); // Looped 1 etc.
        	times += 1;
          }
        }
        
      • D

        Example of while loop in d.
        import std.stdio : writefln;
        
        void main()
        {
        	int times = 1;
        
        	while (times <= 5) {
        		writefln("Looped %d", times); // Looped 1 etc.
        		times += 1;
        	}
        }
        
      • Php

        Example of while loop in php.
        <?php
        $times = 1;
        
        while($times <= 5){
        	print("Looped $times"); // Looped 1 etc.
        	$times += 1;
        }
      • Python

        Example of while loop in python.
        times = 1
        
        while times <= 5:
        	print(f'Looped {times}') # Looped 1 etc.
        	times += 1
        
      • Go

        Example of while loop in go.
        package main
        
        import "fmt"
        
        func main() {
        	var times int = 1
        
        	for times <= 5 {
        		fmt.Println("Looped", times) // Looped 1 etc.
        		times += 1
        	}
        }
        
      • Do-While Loops

      • Javascript

        Example of do-while loop in javascript.
        Coming Soon
      • Dart

        Example of do-while loop in dart.
        Coming Soon
      • D

        Example of do-while loop in d.
        Coming Soon
      • Php

        Example of do-while loop in php.
        Coming Soon
      • Python

        Example of do-while loop in python.
        Coming Soon
      • Go

        Example of do-while loop in go.
        Coming Soon