Posts

Showing posts with the label If

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)...

Collections and Control Flow - Conditional Statements

Next - and final - part of Control Flow is all to do with 'conditionals'. This will be linked to 'if' statements. These are a vital part of Swift and hopefully I'll be able to remember some! After that, the course is complete, which means I can crack on with 'functions' next...! If Statements var temperature = 22 if temperature < 18 {          print ( "Wear a light sweater" )      } else {          print ( "No need for a sweater!" ) } A very simple example! I remembered the 'else' clause. This is when the statements evaluate to 'false'.  In the above example, the code runs through to the 'else'/false statement and prints the second line ("No need..."). However, if I made the the temperature higher than 18, then the other statement would. The other aspect of this is using 'else if', which means another condition!  var temperature = 22 if temperatur...

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...