9951 explained code solutions for 126 technologies


rustHow to to create inclusive range in Rust?


Creating inclusive range in Rust is easy and straightforward. The ..= operator is used to create an inclusive range. For example:

let range = 0..=10;

This creates a range from 0 to 10, including both 0 and 10.

Code explanation

  1. let range = 0..=10; - This creates a variable called range and assigns it a range from 0 to 10, including both 0 and 10.

  2. ..= - This is the operator used to create an inclusive range.

Helpful links

Edit this code on GitHub