about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-21 04:20:57 +0000
committerbors <bors@rust-lang.org>2014-08-21 04:20:57 +0000
commite052aa65db534d78579a604002485257166523e2 (patch)
treef583e69c40da91c1f5918e35acdec1d161d0f74c
parent6063f7981f7d40df633a8a5e4326cbb7451a7649 (diff)
parent3f9ff2e85c00ac9bef411c40cf4fa7f3f9a24393 (diff)
downloadrust-e052aa65db534d78579a604002485257166523e2.tar.gz
rust-e052aa65db534d78579a604002485257166523e2.zip
auto merge of #16447 : steveklabnik/rust/guide_vectors_extra, r=brson
Can't believe I forgot this!
-rw-r--r--src/doc/guide.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md
index af4b4ff6565..db2e366b065 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