GET THIS SWIFT COURSE FOR FREE:

Today we will be talking about one of the most popular feature in programming – Loop.

Let’s dive right in!

Your Code Challenge:

This code challenge is a computer science’s classic Algorithm *drum roll please *.

+ Create a new playground for this code challenge called 7DSC-Day3-MinMaxFinder

+ In Swift, you can create a random number by using arc4random()

+ And if you want to have the random number is within the range of 0 to 1000, you can do arc4random() % 1000.

+ Why do we use % modulus operator here? Modulus means you find the remainder of a division. If you 10%3, you get 1.
In other words, the remainder of a division is always from 0 to the divisor – 1.

+ Knowing this trick, we can now create any random number in any range we want.

+ Let’s create an empty array of Int named numbers.

+ Use a for loop so you can add 1000 random numbers that are always less than 1,000,000 to the array.

+ Now, can you find me the minimum number in the array of random numbers. RULE: do not use any other Swift function like min, max to find the number. You have to use a for loop here! And do not use any other functions to sort the array. You have to use for loop! Otherwise there is no point of practicing loop 🙁 This is in red so you know that I’m seriously serious here! 😈

+ Next, can you help me find the maximum number from the array?
Finally, share you Code Challenge solution in the comment section with me below!

+ This is the most fundamental algorithm (a proven system to perform a task) in computer science. I hope you will try to figure this out! Please spend at least 60 minutes on this before you move on and watch the solution video.

Have fun and good luck,

– Duc

Love even more advanced and in-depth training with me? Join Total iOS Blueprint 2 where I share with you how to build 11 iOS apps from scratch with awesome video tutorials just like these.

GET THIS SWIFT COURSE FOR FREE:

********************************
*** ABOUT CODE MASTERY ***
********************************
Code Mastery is hosted by Duc Tran, founder of Developers Academy.

This is his free-style no notes, no teleprompter presentation and live coding broadcast with you guys everyday.

To join Duc’s free courses, register for free at

*************************
*** MEET DUC TRAN ***
*************************

Duc Tran is founder of Developers Academy, one of the world’s leading iOS, Android and Web development trainers.

More than 2,000,000 developers have studied his video trainings; 100,000 developers see his posts each month. Each year, Duc has helped 20,000 plus developers gratudate from his online courses or video series.

*************************************************
*** FREE TRAININGS IN IOS DEVELOPMENT ***
*************************************************
To subscribe and get free tutorials, courses and weekly content, visit me at:
Connect with Duc on facebook:
Tweet him:
Get daily inspiration: