This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var count: Double = -100 | |
| while -100 < 25.0 { | |
| count += -3.75 | |
| } | |
| // Still don't see it? Let's simplify. | |
| var count = -100 | |
| while count < 25 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var count = 0 | |
| while true { | |
| count += 1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var count = 0 | |
| while true { | |
| count += 1 | |
| if count == 100 { | |
| break | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numberToCountBy = 4 | |
| var numberToStartWith = 11 | |
| var currentNumber = numberToStartWith | |
| var sumOfAllNumbers = 0 | |
| while true { | |
| if currentNumber % numberToCountBy != 0 { | |
| currentNumber += 1 | |
| continue | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using arrays | |
| var names = ["Bob", "Mary", "John", "David"] | |
| var separatedNames: String | |
| for name in names { | |
| separatedNames += name + " " | |
| } | |
| // Using dictionaries | |
| var pets = ["Spot": "Dog", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define the function | |
| func addTwoNumbers(number firstNumber: Int,otherNumber secondNumber: Int) -> Int { | |
| let functionResult = firstNumber + secondNumber | |
| return functionResult | |
| } | |
| // Call the function | |
| var result = addTwoNumbers(number: 5, otherNumber: 3) | |
| // result is equal to 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addTwoNumbers(_ firstNumber: Int, otherNumber secondNumber: Int) -> Int { | |
| return firstNumber + secondNumber | |
| } | |
| // calling the function | |
| var result = addTwoNumbers(5, otherNumber: 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addTwoNumbers(_ firstNumber: Int, secondNumber: Int) -> Int { | |
| return firstNumber + secondNumber | |
| } | |
| var result = addTwoNumbers(5, secondNumber: 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func add(_ firstNumber: Int, to: secondNumber) -> Int { | |
| return firstNumber + secondNumber | |
| } | |
| let result = add(5, to: 25) | |
| print(result) // displays "30" in the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func somethingWentWrong() { | |
| print("Aww...") | |
| } | |
| if a < b { | |
| if sunIshShining { | |
| if madeCupOfCoffee { | |
| print("Yay!") | |
| } else { | |
| somethingWentWrong() |