Welcome back to {Kids: Code} for our seventh issue. This week we’re gonna continue reviewing the different kinds of iterations you’ll come across while also sharing new ways to learn about Swift, the programming language used on Apple devices like the iPhone, iPad, or a Mac. If you’ve always wanted to make apps for the iPhone, be sure to check out our recommendations below!
As always, {Kids: Code} can improve with the help of reader feedback. If you ever have any questions, comments, or concerns, feel free to reach out!
Last week, we took a look at iterating - basically, repeatedly running some code until a condition is met. This week, let's expand on it by looking at a useful trick that often uses iteration behind the scenes.
Let's say you have an Array (or List) of animals, and you want to print them in alphabetical order... but they're not in that order.
``` python
animals = ["cat", "dog", "bird", "rabbit"]
for animal in animals:
print(animal)
# Prints:
# cat
# dog
# bird
# rabbit
```
Putting them into order, in programming, is called sorting. There are many different types of sorting (some more complicated than others), but for the sake of this example we'll go ahead and show how to sort them in alphabetical order.
Python makes this a one line trick - we just have to call `sort()` on our Array.
```python
animals = ["cat", "dog", "bird", "rabbit"]
# Sort in alphabetical order!
animals.sort()
for animal in animals:
print(animal)
# Prints:
# bird
# cat
# dog
# rabbit
```
What if we wanted to sort them in reverse alphabetical order? In this case, we can pass a special bit of code to `.sort()`. We call this an argument, which in this case is `reverse`:
```python
animals = ["cat", "dog", "bird", "rabbit"]
# Sort in reverse alphabetical order
animals.sort(reverse=True)
for animal in animals:
print(animal)
# Prints:
# rabbit
# dog
# cat
# bird
```
Sorting is, thankfully, a pretty universal concept for programming - you'll find it in just about every language, from Scratch to Python to Swift and more. It’s a handy tool when dealing with a large list of items and can be experimented with in many different ways. Why not try coming up with your own list and sorting it in your favorite programming language?
One of the most important things we try to get across here at {Kids: Code} is that kids of all ages can not only code amazing ideas into reality, but also teach others how to do the same. This week we want to shine a light on Benjamin Lee, a 13-year old boy who has been teaching coding for a couple years now.
Benjamin created a website called Epic MC Modly as a way to allow others to mod the video game Minecraft. He’s used this platform to teach computer programming and is using it for an upcoming event on May 31st called “Minecraft Modding: Social Distancing."
This is a tutorial on both coding and Minecraft mods while also serving to raise awareness to the importance of social distancing. If you're a Minecraft fan and familiar with the programming language Scratch (if you've been following this newsletter, there's a good chance you are!) then you might feel right at home with what he's showcasing.
You can read more about the event and Benjamin by clicking here.
When we first launched {Kids: Code} we took a glimpse at the world of Swift, the programming language used to make apps for the iPhone, iPad, and Mac. Since it’s been quite some time since then we thought we’d come back and give some recommendations on ways to get started.
Swift Playground is a clear starting point in learning how to make games for your Apple device. Featuring a variety of visually engaging tutorials and challenges published by Apple themselves, this is a great and free way to check out this programming language. It’s available for Mac and iPad (not iPhone, unfortunately!)
Coding iPhone Apps for Kids: A Playful Introduction to Swift by Gloria Winquist and Matt McCarthy is a great option if a book is more your learning style. You’ll take on unique challenges that guide you through the basics of coding while building apps like a birthday tracker and a platforming game.
That’s not all - this book will not only give you the basics on making these ideas come to life, but it’ll also show you different ways to experiment with them too, like by adding notifications to your birthday tracker or creating animations and high scores for your game. It is available for both paperback and Kindle. (Ages 10+)
This Issue's Vocabulary Word
Sorting
When an algorithm puts a list (called an Array) into a specific order. A list can be sorted in many different ways like alphabetically or by number of letters.