Skip to content

Commit

Permalink
Guide: array subscript notation
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Aug 14, 2014
1 parent c7d0b52 commit 3f9ff2e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/doc/guide.md
Expand Up @@ -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
Expand Down

5 comments on commit 3f9ff2e

@bors
Copy link
Contributor

@bors bors commented on 3f9ff2e Aug 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at steveklabnik@3f9ff2e

@bors
Copy link
Contributor

@bors bors commented on 3f9ff2e Aug 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging steveklabnik/rust/guide_vectors_extra = 3f9ff2e into auto

@bors
Copy link
Contributor

@bors bors commented on 3f9ff2e Aug 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steveklabnik/rust/guide_vectors_extra = 3f9ff2e merged ok, testing candidate = e052aa6

@bors
Copy link
Contributor

@bors bors commented on 3f9ff2e Aug 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e052aa6

Please sign in to comment.