-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.swift
64 lines (53 loc) · 1.36 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import UIKit
/*
'Functions' in Swift
01 'Simple Function'
02 'Passing value' through a 'Function'
03 'Return values' from a 'Function' basis on 'Data Types'
04 Why do I need underscores in swift?
*/
// 'Simple' Function
func greeting1() {
print("This is a sample function")
}
greeting1()
// 'Passing value' through a 'Function'
func greeting2(passingValue: String){
print("Hello \(passingValue)")
}
greeting2(passingValue: "This is a passed value through a function")
// 'Return values' from a 'Function' basis on 'Data Types'
// Returns a 'Boolean' value
func greeting3(name: String) -> Bool {
if name == "Nadhu" || name == "Chammy" {
return true
} else {
return false
}
}
var doorShouldOpen = greeting3(name: "Chammy")
print(doorShouldOpen)
// Returns a 'String' value
func greeting4(name: String) -> String {
if name == "Nadhu" || name == "Chammy" {
return "true"
} else {
return "false"
}
}
var doorOpen = greeting4(name: "Nadhu")
print(doorOpen)
// Function 'with underscore(_)'
func divmod1(_ a: Int, _ b:Int) -> (Int, Int) {
return (a / b, a % b)
}
print(divmod1(7, 3))
print(divmod1(5, 2))
print(divmod1(12,4))
// Function 'without underscore(_)'
func divmod2(a: Int, b:Int) -> (Int, Int) {
return (a / b, a % b)
}
print(divmod2(a: 7, b: 3))
print(divmod2(a: 5, b: 2))
print(divmod2(a: 12,b: 4))