Skip to content

Commit e052aa6

Browse files
committed
auto merge of #16447 : steveklabnik/rust/guide_vectors_extra, r=brson
Can't believe I forgot this!
2 parents 6063f79 + 3f9ff2e commit e052aa6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/doc/guide.md

+13
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,19 @@ for i in vec.iter() {
15711571

15721572
This code will print each number in order, on its own line.
15731573

1574+
You can access a particular element of a vector, array, or slice by using
1575+
**subscript notation**:
1576+
1577+
```{rust}
1578+
let names = ["Graydon", "Brian", "Niko"];
1579+
1580+
println!("The second name is: {}", names[1]);
1581+
```
1582+
1583+
These subscripts start at zero, like in most programming languages, so the
1584+
first name is `names[0]` and the second name is `names[1]`. The above example
1585+
prints `The second name is Brian`.
1586+
15741587
There's a whole lot more to vectors, but that's enough to get started. We have
15751588
now learned all of the most basic Rust concepts. We're ready to start building
15761589
our guessing game, but we need to know how to do one last thing first: get

0 commit comments

Comments
 (0)