rustLoop counter example in Rust
Loop counter example in Rust is a way to iterate over a collection of items and perform an action on each item. The most common way to do this is with a for
loop. The for
loop takes a variable, called a counter, and assigns it a value from the collection. The loop then executes a block of code for each value of the counter.
for counter in 0..10 {
println!("Counter is {}", counter);
}
Output example
Counter is 0
Counter is 1
Counter is 2
Counter is 3
Counter is 4
Counter is 5
Counter is 6
Counter is 7
Counter is 8
Counter is 9
Code explanation
for
loop: the loop that iterates over the collection of itemscounter
: the variable that is assigned a value from the collection0..10
: the range of values that the counter will takeprintln!
: the function that prints out the value of the counter
Helpful links
Related
- How to loop until error in Rust
- Rust for loop range inclusive example
- How to do a for loop with index in Rust
- How to iterate in pairs in Rust
- Rust parallel loop example
- Rust negative for loop example
- How to iterate over string in Rust
- How to iterate linked list in Rust
- How to sleep in a loop in Rust
- How to iterate over ndarray rows in Rust
More of Rust
- How to use regex to match a double quote in Rust?
- How to get a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to parse JSON string in Rust?
- How to use regex to match a group in Rust?
- How to use regex with bytes in Rust?
- How to replace all using regex in Rust?
- Hashshet example in Rust
- How to replace a capture group using Rust regex?
- How to replace all matches using Rust regex?
See more codes...