diff options
| author | srinivasreddy <thatiparthysreenivas@gmail.com> | 2016-03-02 20:31:26 +0530 |
|---|---|---|
| committer | srinivasreddy <thatiparthysreenivas@gmail.com> | 2016-03-02 20:35:30 +0530 |
| commit | a3c9afa841aba127edac2bb60e2f2a720a51d8ac (patch) | |
| tree | 72415e6fe0e12a4671fef6ef73ced91db6672e71 /src/doc | |
| parent | 9bf73d24d0fdc4f6dbca702ec85c5583abc921cd (diff) | |
| download | rust-a3c9afa841aba127edac2bb60e2f2a720a51d8ac.tar.gz rust-a3c9afa841aba127edac2bb60e2f2a720a51d8ac.zip | |
addressed review comments - grammar corrections, space additions
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/book/vectors.md | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index 0eba4d40ede..d9379117c86 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -114,30 +114,37 @@ for i in v { println!("Take ownership of the vector and its element {}", i); } ``` -Note: You cannot use the vector again once you have iterated with ownership of the vector. -You can iterate the vector multiple times with reference iteration. For example, the following -code does not compile. + +Note: You cannot use the vector again once you have iterated by taking ownership of the vector. +You can iterate the vector multiple times by taking a reference to the vector whilst iterating. +For example, the following code does not compile. + ```rust let mut v = vec![1, 2, 3, 4, 5]; + for i in v { println!("Take ownership of the vector and its element {}", i); } + for i in v { println!("Take ownership of the vector and its element {}", i); } ``` + Whereas the following works perfectly, ```rust let mut v = vec![1, 2, 3, 4, 5]; + for i in &v { - println!("A mutable reference to {}", i); + println!("This is a reference to {}", i); } for i in &v { - println!("A mutable reference to {}", i); + println!("This is a reference {}", i); } ``` + Vectors have many more useful methods, which you can read about in [their API documentation][vec]. |
