Skip to Content
Learn
Loops
Review
for _ in 1...10 { print("Great job!") } print("Now time to review loops!")

The above syntax should now look familiar!

In this lesson, we went over:

  • Manually repeating tasks.
  • for-in loops are used to iterate over collection items like ranges and strings.
  • stride() creates a range that we can customize.
  • _ usage when we don’t need to use the placeholder variable.
  • continue allows us to move on to the next value.
  • break stops the loop before the stopping condition is met.
  • while loops are used when we don’t know how many times we’re looping.

Instructions

1.

If you want to challenge yourself:

  • Create a loop that iterates from 1 to 100 that prints out whether the current number in the iteration is even or odd.
  • Use a loop to determine if a number is a prime number.
  • Loop through a string and count how many characters are in it.
  • Recreate the follow pattern using loops:
* ** *** ****
Folder Icon

Take this course for free

Already have an account?