Programming-Idioms

History of Idiom 2 > diff from v8 to v9

Edit summary for version 9 :

Version 8

2015-08-21, 07:42:46

Version 9

2015-08-21, 08:30:22

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Code
for _ in 0..10 { println!("Hello"); }
Code
for _ in 0..10 { println!("Hello"); }
Comments bubble
0..10 syntax creates range iterator.

You can leave out variable name with underscore if you do not want to use it.
Comments bubble
0..10 syntax creates range iterator.

You can leave out variable name with underscore if you do not want to use it.
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20for%20_%20in%200..10%20%7B%0A%20%20%20%20%20%20%20%20println!(%22Hello%22)%3B%0A%20%20%20%20%7D%0A%7D&version=stable