Join Harrison Ferrone for an in-depth discussion in this video Use for-in loops, part of Learning Swift 3 for Developers.
- [Voiceover] In languages like C# and C++,…for and for each loops are used…in a variety of computations.…In Swift, we use a for-in loop for those cases,…like looping through collections.…Let's take a look at a basic for-in loop,…and then go over some more real world use cases.…Make some room underneath our if-else statements,…and add a comment.…Using for-in loops.…
Let's start with a basic for-in loop…that just loops through an integer range.…For I in one to five,…will simply print out I.…If you expand the debug window a little bit,…you'll see one, two, three, four, five.…Alright, now for a more practical example.…Let's recreate our item array from the last section…and iterate through it, printing out each item.…Variable item array equals…item one, item two, and item three.…
Now, for a for-in loop, we say for every item…in item array,…print out the item.…In our debug log, we see item one, item two, and item three.…Since arrays are ordered, that is,…the order you added items to the array…is the order they will be iterated over,…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- 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.