From fbadb36c2bb53c40299744ff2c5cbc032a1ea7c7 Mon Sep 17 00:00:00 2001 From: Eduard Bopp Date: Mon, 10 Feb 2014 22:33:09 +0100 Subject: Document for-loop in tutorial section on loops --- src/doc/tutorial.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/doc/tutorial.md') diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 73fec54fbcb..a7e1b2b64c6 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -582,6 +582,18 @@ loop { This code prints out a weird sequence of numbers and stops as soon as it finds one that can be divided by five. +There is also a for-loop that can be used to iterate over a range of numbers +(or, more generally, anything implementing the `Iterator` trait): + +~~~~ +for n in range(0, 5) { + println!("{}", n); +} +~~~~ + +The snippet above prints integer numbers under 5 starting at 0. + + # Data structures ## Structs -- cgit 1.4.1-3-g733a5