Control Flow In Swift

Updated 2 December 2021


In this blog, we will know about control flow in swift

There are multiple types of control flow in swift:-

  1. while loop
  2. for-in loop
  3. if else
  4. guard
  5. switch

1. While-loop:-

While loop will perform on a single condition. It will perform until the condition will false.

the flow of the while loop:-

1. It will check the condition
2. if it is true
3. then it will execute the statement
4. if it is false
5. then it will not execute the statement

for example

2. For – in loop:-

In this loop we can perform the statement until the condition



the flow of the for in loop:-

1. it will check the condition

2. if it is true
3. then it will execute the statement

4. it will increase the value of val
5. if it is false
6. then it will not execute the statement

3. If-else

it will compare the two objects and on the result of the comparison it will perform the statement



4. Guard

It works the same as if-else it will check the condition and perform accordingly



if obj1 has nil value then it will perform return and if it has value then it will assign value in obj2

5. Switch

It will perform like if-else but it is different from the if-else

in switch it will check the each condition and if it is matched to any one it will stop the matching with other

it has a default statement if there is not any matched statement then it will perform default statement


for example

call the function checkswitch with the integer parameter


I hope this blog will help you to understand Swift control flow if you have any comments, questions, or recommendations, feel free to post them in the comment section below!

For other technical blogs, please click here.

If you want to know more about swift please check here

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home