Join Abhiram Ravikumar for an in-depth discussion in this video Control flow: For loops, part of First Look: Rust.
- [Abhiram] We can use the for loop and execute some code…for each item in a collection.…Let's first declare an array a, with five elements in it.…We use the let keyword, let a=…and inside the square brackets,…we have an array with five elements.…Use the for keyword to initiate the for loop.…So for element in a.iter.…
Here, we're using the iter method.…The iter method creates an object which can iterated,…one element at a time.…So at a given point of time,…element will have one particular value of the array.…So every time the for loop executes,…element now points to each iterable element in the array.…Now let's go ahead and print the value here.…So let's do a println here…so that prints on a new line each time.…
And we have a place holder here…and inside the for loop, we're using element.…So let's go ahead and save this.…Let's open the command prompt and run our code.…So as you can see in the last five lines here,…on each line, element points to one value of the array…and that gets printed.…Note that we don't need to explicitly deal with indexes…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
Programming Foundations: Data Structures (2014)with Simon Allardice2h 29m Intermediate
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.