Logo

Programming-Idioms

History of Idiom 2 > diff from v52 to v53

Edit summary for version 53 by Bzzzzzzzz:
New D implementation by user [Bzzzzzzzz]

Version 52

2016-11-30, 20:17:50

Version 53

2017-08-06, 15:36:05

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Illustration

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Illustration
Imports
import std.stdio : writeln;
import std.range : iota;
import std.algorithm.iteration : each;
Code
void main(){iota(0,10).each!(a => "Hello".writeln);}
Comments bubble
iota generate an iterable sequence.
each is a higher order function.
Hello is written using UFCS in a delegate literal.
Doc URL
https://dlang.org/phobos/std_algorithm_iteration.html#each
Demo URL
http://ideone.com/MjsOpv