Always prioritize parameters (placeholders) over arguments (actual values).
funcprintTimesTables(number: Int, end: Int) {for i in1...end {print("\(i) x \(number) is \(i * number)") }}printTimesTables(number:5, end:20)/*5: argumentnumber: parameter20: argumentend: parameterWhichever you choose, you should place them in the order they were listed when you created the function.E.g. you cannot write "printTimesTables(end: 20, number: 5)" swift will not allow it*/
Random Number in a defined range until a particular target
// create an integer to store our rollvar roll =0// carry on looping until we reach 20while roll !=20 {// roll a new dice and print what it was roll =Int.random(in:1...20)print("I rolled a \(roll)")}// if we're here it means the loop ended – we got a 20! print("Critical hit!")/*print:I rolled a 11I rolled a 14I rolled a 3I rolled a 16I rolled a 10I rolled a 9I rolled a 9I rolled a 12I rolled a 3I rolled a 12I rolled a 9I rolled a 17I rolled a 15I rolled a 20Critical hit!*/
let scores = [1, 8, 4, 3, 0, 5, 2]var count =0for score in scores {if score ==0 {break } count +=1}print("You had \(count) scores before you got 0.")// print: You had 4 scores before you got 0.