Learn Before
Concept
for - Rust Programming
In Rust programming, a "for loop" is a type of loop that allows you to iterate over a collection of items, such as an array or a vector. The basic syntax of a for loop in Rust is as follows:
for variable in collection { // code to execute for each item in the collection }
For example, you can use a for loop to iterate over an array of integers and print out each value:
let numbers = [1, 2, 3, 4, 5]; for num in numbers.iter() { println!("{}", num); }
In this example, the for loop iterates over the numbers array, assigns each value to the variable num, and prints the value of num at each iteration.
0
1
Updated 2023-02-03
Tags
Object-Oriented Programming