From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Nested loops
- [Narrator] In rust, multiple loops can be nested inside of one another. And one common reason for doing that is to process the elements of a multi-dimensional array. Let's say we want to display the elements of this three by three array named matrix. Since this is a two dimensional array we can use a pair of nested four loops to iterate through it and individually access each of the elements. Each iteration of the outer loop, iterating over the matrix or return a one-dimensional sub-array which we'll call a row. Then we'll use an inner loop to iterate through each row and return each of the elements, which will be numbers. Finally, within that inner loop, we'll print each number. Notice that I'm using print rather than print line, which means this print statement will not add a new line at the end of the string. Also notice I'm using this special sequence backslash T which we haven't encountered yet. This will insert a tab…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Conditional execution3m 38s
-
(Locked)
Multiple conditions3m 45s
-
(Locked)
Conditional assignment3m 41s
-
(Locked)
Loops3m 45s
-
(Locked)
While loops4m 55s
-
(Locked)
For loops6m 35s
-
(Locked)
Nested loops2m 51s
-
(Locked)
Challenge: Max, min, mean1m 13s
-
(Locked)
Solution: Max, min, mean2m 25s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-