Logo

Programming-Idioms

History of Idiom 2 > diff from v58 to v59

Edit summary for version 59 by kai:
[Rust] Using 0..10 prints "hello" 11 times

Version 58

2018-03-06, 16:07:00

Version 59

2018-04-15, 01:46:23

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 0..10 { println!("Hello"); }
Code
for _ in 1..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