Test your Programming knowledge

50% users failed to get the best score. It's your turn to test now.
Questions curated by the expert mentors at codzify.com

Start Quiz


Swift Decision Making with practical example

2 mins 51 sec read

Swift Decision Making

Sometimes in a program we need to test a condition. If condition is true we perform first action and if 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' .

Recommended Articles

Did you found this article helpful?

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor