diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-08-12 08:17:08 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-08-14 16:06:23 -0400 |
| commit | 3f9ff2e85c00ac9bef411c40cf4fa7f3f9a24393 (patch) | |
| tree | 692589268977334dc6071e0b53ba45396d3fd721 | |
| parent | c7d0b5259d95ab4ef821bdf93a434538c3a84dad (diff) | |
| download | rust-3f9ff2e85c00ac9bef411c40cf4fa7f3f9a24393.tar.gz rust-3f9ff2e85c00ac9bef411c40cf4fa7f3f9a24393.zip | |
Guide: array subscript notation
| -rw-r--r-- | src/doc/guide.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md index ecde51538e2..c2d019e3c4a 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -1571,6 +1571,19 @@ for i in vec.iter() { This code will print each number in order, on its own line. +You can access a particular element of a vector, array, or slice by using +**subscript notation**: + +```{rust} +let names = ["Graydon", "Brian", "Niko"]; + +println!("The second name is: {}", names[1]); +``` + +These subscripts start at zero, like in most programming languages, so the +first name is `names[0]` and the second name is `names[1]`. The above example +prints `The second name is Brian`. + There's a whole lot more to vectors, but that's enough to get started. We have now learned all of the most basic Rust concepts. We're ready to start building our guessing game, but we need to know how to do one last thing first: get |
