Coding at Home: April 22nd, while loops

Catch us today at 1pm, Irish time, for some more live coding!


We finished up logical operators yesterday with a little BuzzFeed-style quiz. Our code looked a little something like this:

show("What is your name?")
let name = ask("Name")
show("Hi " + name)
show("Answer some questions and I'll tell you what type of animal you are.") 

show("Are you house-trained?")
var isHouseTrained = askForBool()

show("If I threw a ball would you chase it?")
var wouldChaseBall = askForBool()

if isHouseTrained && wouldChaseBall {
    print("You're a 🐶!")
} else if !isHouseTrained && wouldChaseBall {
    print("You're a 🐺!")
} else if isHouseTrained && !wouldChaseBall {
    print("You're a 🐱!")
} else if !isHouseTrained && !wouldChaseBall {
    print("You're a 🦁!")

Paste that into a Swift Playground on your iPad and try it out!

Today’s Session

Today we’re back with while loops.

They require a little more design thinking, and especially today’s playground, where we nest loops! This just means we’ll be running a loop inside of a loop.

Because this is a little bit of a leap, conceptually, we’re going to take our time and come up with some strategies for reading code that might help you. Not only will they make reading code someone else has written easier, they’ll make reading and explaining your own code later easier. And the tips will help you design your code better, before you even start writing a single line.

If you need to catch up on while loops, feel free to watch (or re-watch) yesterday’s session.

We’ll see you at 1pm!

Leave a Reply

Your email address will not be published. Required fields are marked *