Posts

Showing posts with the label Bool

Nick Walter Challenges (Part 2)

So 5 days without coding is a poor effort! I have a very small amount of time (20 minutes) to do some then I will make up for it by doing more at the weekend. As it's a short time, I'm going straight back to Nick Walter's challenges, rather than Angela's more in-depth and theoretical stuff. Right here we go! Start time - 15:55 Print and comments // 1) Write a single line comment // 2) Write a multi line comment // 3) Print a String, Int and Double all in one print statement These should all be fine. Let's do it! // Here is my single line comment /* Multi line comment:  This will go over several lines  No problem at all  */ var name = "Josh" var myAge = 33 var shoeSize = 8.5 print ( "My name is \ ( name ), my age is \ ( myAge ) and my shoe size is \ ( shoeSize )" ) All easy peasy! Boolean and If Statements //1) Make a boolean variable that's true //2)...

Ray Wenderlich Course Part 7 (up to lesson 62)

First of all, I DID IT! I managed to use if statements to program in a maximum with five rounds and the total score being shown. Wasn't easy but I did it! func nextRound() {                          score += points             roundNumber += 1         }                  if difference == 0 && roundNumber < 5 {                          title = "Perfect!"             points += 100             nextRound ()                      } else if difference < 5 && roundNumber < 5 {             title = "Very close - great try!"             ...

Numbers and Booleans; Type Safety and Type Inference

So, yes I am on much more of a roll now! The most consistent entries since starting this blog! As before, the issue will be, once the recap/consolidation process is complete, trying to stick to learning new aspects regularly will be the challenge. Anyway, we're cracking on with numbers and booleans first of all.... Numbers and Booleans  One of the concepts mentioned are floats - numbers which can have decimal places. I know that these are known as 'doubles' and tend to use these over 'floats'. And that's what he goes on to say! Indeed, Pasan explains that Double is preferable as it can store more basically. A lot of this is linked to type inference to e.g. if I declare a variable and give it 3.4 as a value, it will automatically make it of type Double. Booleans - now these are essentially true or false. String Interpolation - as a reminder - allows values from different types to be put in together. You can create a string made up of a mixture of other type...

What I know about Swift - Part Two

I don't know how many parts I will need for explaining what I know about Swift - this may be the last one! Another note - I'm writing this without ANY reference to Swift documentation/information - it is a pure test to see what I know! In the previous entry, I described how I went about learning Swift, with the timeframe that included the learning-forgetting-relearning cycle, which I am desperate to break. Last time it was the basics about variables, constants, numbers and strings. This time it gets a little more complicated... Boolean I believe that this comes from the (mathematician?) George Boole, who worked with absolutes: true or false. To apply this to Swift, it could be to find out whether a calculation is true or not. E.g. 7 > 4 would return "true" Using the <, > (along with the = for each) symbols means that you can test to see if a value is greater than another. Conditionals The above directly links to the use of the if/else stateme...