// plain
Iterating over a struct in Rust is done using a for
loop. The syntax is as follows:
for element in struct {
// code to execute
}
for
: the keyword used to start the loopelement
: the variable used to store each element of the structin
: the keyword used to indicate the struct to iterate overstruct
: the name of the struct to iterate over{
: the opening brace of the loop// code to execute
: the code to execute for each element of the struct}
: the closing brace of the loop
group: rust-struct