How to use For Each Loops in Swift | Swift Basics #15

  Рет қаралды 5,796

Swiftful Thinking

Swiftful Thinking

Күн бұрын

Master the usage of for-each loops in Swift with this comprehensive tutorial! Learn how to iterate over arrays, sets, dictionaries, and other collections using for-each loops. Discover the power of simplified syntax and improved readability when working with loops in Swift. Gain a deep understanding of how for-each loops can streamline your code and make it more efficient. Start your journey to becoming a proficient Swift developer today and leverage the flexibility and convenience of for-each loops in your projects!
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno
00:00 Loops
00:00 Intro
01:44 Welcome back!
02:37 For Loops
05:06 Looping on an array of data
06:28 Checking data in the loop
09:24 Enumerated arrays
11:25 Control flow (break & continue)
13:56 Other types of loops
15:33 Wrapping up

Пікірлер: 18
@gregas3068
@gregas3068 Жыл бұрын
NIce style of explanation . . Learning a lot from you, mister. Keep doing good work.
@programingwithabhi2631
@programingwithabhi2631 7 ай бұрын
Thanks for video Man 😄
@thahaziq97
@thahaziq97 Жыл бұрын
Thank you!!
@swanswann5932
@swanswann5932 Жыл бұрын
Thanks a lot!
@tylerwu2023
@tylerwu2023 8 ай бұрын
THX Nick
@vazzhh
@vazzhh 8 ай бұрын
thanks a lot
@arrowfunction3200
@arrowfunction3200 Жыл бұрын
i love you
@CMessineo
@CMessineo 5 ай бұрын
Quick question: on your screen when you loop from 0 to
@SwiftfulThinking
@SwiftfulThinking 5 ай бұрын
This sounds like it’s correct. We’re looping 100 times from 0 to less than 100, so the first loop is 0 and last loop is 99.
@CMessineo
@CMessineo 5 ай бұрын
@@SwiftfulThinking What's odd is that the display looks different than the display on your screen. The code works fine, I'm just not sure what is making my Xcode look different than yours. I hope I didn't accidentally mess something up.
@SwiftfulThinking
@SwiftfulThinking 5 ай бұрын
@@CMessineoegh don’t worry about it too much 😅 as you start building screens it will clear itself up
@CMessineo
@CMessineo 5 ай бұрын
@@SwiftfulThinking Cool, looking forward to it!
@thedrenkemp4462
@thedrenkemp4462 Жыл бұрын
for (index, lesson) in allLesson.enumerated(){ if index == 1 { break } print("index: \(index) || lesson: \(lesson)") } why do this return a different output then this ? for (index, lesson) in allLesson.enumerated(){ if index == 1 { print("index: \(index) || lesson: \(lesson)") break }
@sattorjabborov2728
@sattorjabborov2728 Жыл бұрын
In the second one, you are printing before breaking the loop so it will print index 1 too and break the loop, while in the first one, print statement comes after the condition so it will check the condition first. If the break line hits inside that condition, the code after that {...} will no longer be executed
@lolrie
@lolrie Жыл бұрын
The code executes line by line in order. In the first one... - We start with index = 0. Index 0 is not one, so it skips that entire { } closure and proceeds to the next item, which prints the statement. - Now continuing the loop, we go back to the top with index = 1. Index 1 is equal to 1, so it executes the code in the closure, which is "break." Break means immediately break out of / exit the function and forget the rest. So it never even reaches the print( ) function. In the second one... - We start with index = 0. Index 0 is not 1, so it skips over that { } closure entirely, which means it will not print( ) and it will not break out of the function. - Now continuing the loop, we go back to the top with index = 1. Index 1 is equal to 1, so it executes the code in the closure, which is first print( ) and then break. So it will print the string for index = 1, and then exit the function entirely from there.
@Bob-hh5cp
@Bob-hh5cp Жыл бұрын
In the first one, you are saying "break out of the function when index == 1" In the second one, you are saying "print the values when index == 1 THEN break out of the function" The position you place a break statement in can cause a lot of difference.
@besmart1.0
@besmart1.0 18 күн бұрын
let bestTeacherEver: String = "Nick" print(bestTeacherEver)
@erenunal1512
@erenunal1512 12 күн бұрын
use var. Because he is not immutable. He is better everyday.
How to Filter, Sort, and Map in Swift | Swift Basics #16
16:26
Swiftful Thinking
Рет қаралды 6 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 30 МЛН
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 25 МЛН
Learn Go in 12 Minutes
13:34
Jake Wright
Рет қаралды 944 М.
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 82 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Рет қаралды 42 М.
Swift Closures Explained
14:23
Sean Allen
Рет қаралды 62 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 799 М.
Become a SwiftUI Expert - Learn Data Handling in this Epic Masterclass!
36:41
Rebeloper - Rebel Developer
Рет қаралды 1,9 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 30 МЛН