Skip to Content
Beginning Rust: Get Started with Rust 2021 Edition
book

Beginning Rust: Get Started with Rust 2021 Edition

by Carlo Milanesi
January 2022
Beginner content levelBeginner
424 pages
8h 8m
English
Apress
Content preview from Beginning Rust: Get Started with Rust 2021 Edition
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-7208-4_15

15. Ranges and Slices

Carlo Milanesi1  
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How to use closed ranges and open-ended ranges, both right-exclusive and right-inclusive

  • How to define and use slices of arrays, vectors, or other slices, using ranges

The Ranges

We already saw a way to write a for loop:
for i in 0..12 { println!("{}", i); }
But there is another possible way to write it:
let dozen = 0..12;
for i in dozen { println!("{}", i); }

This shows that the 0..12 clause is not a part of the for statement syntax, but it is an expression, whose value can be assigned to a variable; that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust for Absolute Beginners: Learn Rust in 4 Hours

Rust for Absolute Beginners: Learn Rust in 4 Hours

Ajay R. Warrier
Programming with Rust

Programming with Rust

Donis Marshall

Publisher Resources

ISBN: 9781484272084Purchase LinkPublisher Website