Swift if, if...else Statement

2 mins 51 sec read

Sometimes in a program we need to test a condition. If that condition is true we perform first action and if the condition is false we perform second action.

Now what does that mean?

1) Simple if Statement

if statement is used to test a given condition. If given condition is satisfied then only block inside if statement will gets executed.

Example :-

import UIKit
var a:Int = 10

if(a == 10)
{
 print("a = (a)")
}

Output :-

a = 10

In this swift program we first initialised a variable "a" with value "10" . Then if condition checks wether 'a == 10' or not . Since value matches block inside if is executed. That's why output 'a = 10' .

Previous Next




Codzify Web Stories

Upskill yourself!


Roadmap to Programming Languages

799 1999 /month


Course Duration: 3 Months.

Mode of Learning: You will get Weekly 3 recorded videos on Monday, Wednesday & Friday.

Live Doubt Sessions: Every Saturday 1 hour, you can opt-for live doubt session if required.

Practical Assignments: Daily practical Assignments to do based on the concepts you learnt in the class.

Things you'll learn: C, C++, Python Programming languages.

Learn More

Roadmap to become skilled Full Stack Web Developer

999 1999


8 hours on-demand video

Full lifetime access

Certificate of completion

Access on mobile and TV

Live Doubt Sessions: Every Saturday 1 hour, you can opt-for live doubt session if required.

Things you'll learn: Angular, HTML, CSS3, Javascript, Bootstrap 5, Server Side Scripting, Google backed Firebase, Authentication, Payment Methods & more.

Learn More