I am working through some of the Exercism exercises. I am running into an issue when I try to use variables as the bounds for a range. The code I am working on is as follows:
pub fn test(start: i32, end: i32) {
println!("{}-{}", start, end);
for n in start..end {
println!("IN LOOP: {}", n);
}
}
fn main() {
test(7, 5);
}
The issue happens when I try to call this function with any set of start
and end
params. I can see the output from the first println!
call, but the "IN LOOP" print never runs. If I replace this line for n in (start..end)
with something like for n in (3..0)
it runs successfully. I am very curious why it seems like I cannot create a range bounded by variables.
The example is available on The rust playground