iOS Fundamentals — iOS Tour Part 3 (Statements types)

Dipika Kansara
2 min readJan 31, 2022

In this tutorial you will learn some more basic iOS fundamentals like Statements in Swift.

There are three types of statements in swift.

  • Simple statements
  • Conditional Statements
  • Loop Statements

Now let’s jump on our first type of statements in this fundamentals tour of statement.

Type — 1 : Simple Statements:

The simple statement consists of either an expression or declaration. The For example,

var myNumber = 3* 5

print statement we have used earlier is also an example of simple statements.

Type — 2: Conditional Statements:

The Conditional Statement allows us to execute a certain code only when certain conditions are met. There are five types of conditional statements available in Swift.

if statement :

var a = 25
var c = 75
if (a < c) {
print("a is smaller than C")
}

if- else statement :

var a = 25
var b = 50
var c = 75
if (a < c) {
print("a is smaller than C")
}
else {
print ("c is smaller then a")
}

if — elseif statement :

var a = 25
var b = 50
var c = 75
if (a < c) {
print("a is smaller than C")
}
else if (a < b){
print ("a is smaller then b")
}
else {
print("a is bigger than c and b")
}

Nested if else statement :

var a = 25
var b = 50
var c = 75
if a > b {
if a > c {
print("A is big")
}
}
else if b > c {
print( "B is big")
}
else {
print("C is big")
}

Type — 3: Loop Statements:

Loop statements allow us to repeatedly execute a block of code.There are three types of looping statements in Swift.

For in loop :

Swift for loop is used to run a specific code until a certain condition is met.


for i in 1...3 {
print("Hello, World!")
}

While Loop :

Swift while loop is used to run a specific code until a certain condition is met.

var i = 1, n = 5

while (i <= n) {
print(i)
i = i + 1
}

Repeat while Loop:

The repeat while loop is similar to while loop with one key difference. The body of repeat...while loop is executed once before the test expression is checked.

var i = 1, n = 5

repeat {

print(i)

i = i + 1

}
while (i <= n)

After covering conditional and loop statements there are more different statements in swift like Guard statements, Break Statements and continue statements. We will cover more advanced statements in next fundamental tour.

I hope I have covered basic statements in this article of iOS fundamental tour.

Happy Coding 😁

--

--