rust - What is the idiomatic way to write a for loop without using the iterator value? -
assuming want finite loop using range:
let mut x: i32 = 0; in 1..10 { x += 1; } the compiler spit out warning:
warning: unused variable: `i`, #[warn(unused_variables)] on default in 1..10 { ^ is there more idiomatic way write won't make compiler complain?
you can write _ pattern, meaning “discard value”:
let mut x: i32 = 0; _ in 1..10 { x += 1; }
Comments
Post a Comment