Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 723 Bytes

how-to-iterate-over-struct-in-rust.md

File metadata and controls

27 lines (19 loc) · 723 Bytes

How to iterate over struct in Rust

// 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
}

Code explanation

  • for: the keyword used to start the loop
  • element: the variable used to store each element of the struct
  • in: the keyword used to indicate the struct to iterate over
  • struct: 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

Helpful links

group: rust-struct