Programming-Idioms

History of Idiom 2 > diff from v59 to v60

Edit summary for version 60 :
[Rust] my change was wrong, intervals are half open

Version 59

2018-04-15, 01:46:23

Version 60

2018-04-15, 01:48:57

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
Code
for _ in 1..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
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