Days 3 and 4 of 100 Days of Swift

Days 1 to 12 of the “100 Days of Swift” course make up the “Introduction to Swift” section.

Day 3‘s lesson covered operators and conditions. The specific topics were: arithmetic operators, operator overloading, compound assignment operators, comparison operators, if and else/if conditions, how to combine conditions, ternary operator, switch statements, and range operators.

Thoughts about Day 3

This was a well-presented overview of how operators and conditions are handled by Swift. I found Swift’s implementation and usage of operators and conditions easier to use than in Java.

Some notes that I made while working through the Day 3 lesson:

  • In topic “5. Conditions” I learned about the Dragonball Z meme of “It’s over 9000!” from one of the examples given.
  • Pay attention that mixed types are not allowed to be compared against each other.
  • In topic “7. The ternary operator” author Paul Hudson, when it comes to using the ternary operator, is in the “avoid where possible” camp. He doesn’t recommend using the ternary operator because to him the ternary operator can make code harder to read. I prefer using the ternary operator over the if/else where appropriate.
  • In topic “8. The switch statement” Swift’s case statements are not required to be followed by a break statement, unlike with Java. I like that Swift has the ‘fallthrough’ that gives programmers the option to continue code execution from the current case to the next case if wanted.
  • In topic “9. Range operators” I like Swift’s implementation and usage of the half open range operator ..< (which takes the lowest range and up to, but excluding, the upper range) and the closed range operator (which takes the lowest range and up to, and including, the upper range)

It took me 2 hours 15 minutes to go through all of material (videos, main and Optional texts, links to external additional reading materials, and Tests) given for the Day 3 lesson.

After a few hours break I decided to also work through the Day 4 lesson.

Day 4’s lesson covered “loop, loops, and more loops”. The specific topics were: for loops, while loops, repeat loops, exiting loops, exiting multiple loops, skipping items, and infinite loops.

Thoughts about Day 4

Notes that I made while working through the Day 4 lesson:

  • In topic “1. For loops” I like how Swift’s for loop uses a one word variable of my choice to be recognized as the loop’s initialized index counter instead of how it’s done in Java. For example, in Java I’d have to type for (int i = 0; i < 5; i++) while in Swift the equivalent is for i in 0..<5
  • I like that Swift doesn’t require line statements to end with the semi-colon like is required in Java and C.
  • The Test part of each topic do a great job testing if you’re paying attention or not to the code example’s syntax. If I failed a test it was not because I didn’t understand the topic’s concept but because I either didn’t pay attention that a variable being modified was defined as a constant with let, I didn’t pay attention that variables meant to be arrays had their array list surrounded by “( )” instead of “[ ]“, and that loop statements weren’t surrounded by braces “{ }“.

It took me 2 hours 30 minutes to go through all of material (videos, main and Optional texts, links to external additional reading materials, and Tests) given for the Day 4 lesson.


Today’s total study time: 4 hours 45 minutes

100 Days of Swift cumulative study time: 8 hours 30 minutes