Logo

Programming-Idioms

History of Idiom 2 > diff from v92 to v93

Edit summary for version 93 by dude:
[D] reduced excessive indentation caused by TAB

Version 92

2019-09-27, 09:46:57

Version 93

2019-09-27, 16:34:49

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
Imports
import std.stdio
Code
foreach(i; 0..10)
	writeln("Hello");
Code
foreach(i; 0..10)
  writeln("Hello");
Comments bubble
use foreach with a numeric range instead of for whenever possible to avoid subtle errors. Also allows nice type inferrence.
Comments bubble
use foreach with a numeric range instead of for whenever possible to avoid subtle errors. Also allows nice type inferrence.