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

Bad example to show indices begin at 0 #363

Closed
CAESIUS-TIM opened this issue Nov 16, 2023 · 0 comments
Closed

Bad example to show indices begin at 0 #363

CAESIUS-TIM opened this issue Nov 16, 2023 · 0 comments

Comments

@CAESIUS-TIM
Copy link
Contributor

let i = xs.len() + 1;

The given example doesn't effectively show that in Rust, indices start from 0; it might even give the impression that indices begin at 1.

A common mistake is forgetting to subtract 1, as seen here:
Right: let i = xs.len() - 1;
Wrong: let i = xs.len();

CAESIUS-TIM added a commit to CAESIUS-TIM/book that referenced this issue Nov 16, 2023
@CAESIUS-TIM CAESIUS-TIM mentioned this issue Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant