Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide: array subscript notation #16447

Merged
merged 1 commit into from
Aug 21, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
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