Log in from a computer to take this course

You'll need to log in from a computer to start Learn Swift. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Before we get to writing our own loops, let’s explore what programming would be like if we couldn’t use loops.

Let’s say we want to make a program that prints "Hip Hip Hooray!" 5 times:

print("Hip Hip Hooray!") print("Hip Hip Hooray!") print("Hip Hip Hooray!") print("Hip Hip Hooray!") print("Hip Hip Hooray!")

That’s still manageable, we’re writing 5 print() statements (or copying and pasting a few times). But, imagine if we come back to this program and we want to change it to print "Hip Hip Hooray!" 10, or 24601, or … 100000000 times? It would take an extremely long time and by the end, we could still end up with inconsistencies and mistakes.

Don’t dwell too long on this tedious scenario — we’ll learn how loops can help us out in the next exercise. For now, let’s gain an appreciation for loops. 😈

Instructions

1.

Using 16 print() statements, print out: "This can be so much easier with loops!".

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?