Logo

Programming-Idioms

  • VB
  • Obj-C
  • D
import std.stdio;
foreach(i; 0..10)
  writeln("Hello");

use foreach with a numeric range instead of for whenever possible to avoid subtle errors. Also allows nice type inferrence.
import std.stdio : writeln;
import std.range : iota;
import std.algorithm.iteration : each;
iota(0,10).each!(a => "Hello".writeln);

iota generates an iterable sequence of number.
each is a higher order function.
Hello is written using UFCS in a delegate literal.
Imports System
For x = 1 To 10
    Console.WriteLine("Hello")
Next x

Iterate from 1 to 10; print Hello on a new line.
It is optional to include the loop variable in the Next statement.
for (NSInteger i=0;i<10;i++){
NSLog(@"Hello");
}
with Ada.Text_IO;
use Ada.Text_IO;
for I in 1 .. 10 loop
  Put_Line ("Hello");
end loop;

New implementation...
< >
programming-idioms.org