Skip to main content

Control Flow Statements - statements used in swift

List out what is the control transfer statements used in swift

Control flow statements are used to control the flow of execution in a program. There are several types of control flow statements in Swift, including loop statements, branch statements, and control transfer statements. 
1.       Loop statements allow a block of code to be executed repeatedly
2.        Branch statements allow a certain block of code to be executed only when certain conditions are met
3.       Control transfer statements provide a way to alter the order in which code is executed.
4.       Swift provides a do statement to introduce scope, and catch and handle errors,
5.       Defer statement for running cleanup actions just before the current scope exits.

Loop Statements -

Loop statements allow a block of code to be executed repeatedly, depending on the conditions specified in the loop.
Swift there are three loop statements
·         For-in statement
·         While statement
·         Repeat-while statement
A for-in statement allows a block of code to be executed once for each item in a collection that conforms to the Sequence protocol.
for item in collection {
A while statement allows a block of code to be executed repeatedly, a condition remains true.
while condition {
A repeat-while statement allows a block of code to be executed one or more times, then condition true.
repeat {
} while

Branch Statements

Branch statements allow a certain block of code to be executed only when certain conditions are met. Swift have three branch statements
·         if statement
·         guard statement
·         Switch statement
Guard Statement
A guard statement is used to transfer program control out of a scope if one or more conditions aren’t met.
guard condition else {
Switch Statement
A switch statement allows certain blocks of code to be executed depending on the value of a control expression.
switch control expression {
case pattern 1:
case pattern 2 where condition:
case pattern 3 where condition,
     pattern 4 where condition:

Control Transfer Statements

Control transfer statements can change (alter) the order in which code in your code is executed.
 Swift have five control transfer statements
·         break statement,
·         continue statement - A continue statement ends program execution of the current iteration of a loop statement 
·         fallthrough statement
·         return statement
·         throw statement


  1. Thanks for the useful information, give more updates like First time I visit your site really nice, here after a daily visit.
    ecommerce website development company in chennai


Post a Comment

Popular posts from this blog

How Create Animated Circle Progress Bar iOS 11 Swift 4

Animated Circle Progress Bar iOS 11 Swift 4

With MBCircularProgressBar -

A circular, animatable & highly customizable progress bar from the Interface Builder Swift, Using pod fite MBCircularProgressBar Installation Cocoapods terminal.

pod "MBCircularProgressBar"

That - A Simple Steps to installed pod file -        Open terminal       Command on terminal go to project folder Cd path       set your project path on terminal.       command : pod init       open pod file - open -e podfile       added in pod file with in : pod "MBCircularProgressBar"       Command : Pod install       Close project of Xcode       open your Project from terminals       Command : open PodDemos.xcworkspace After opern StoryBoard and Now drag a UIView over the viewController in storyboard

Or set UIView Constraint width, height or verticle or horzentail space and set a class MBCircularProgressBarView in StoryBoard. Open Atribute inspector and cu…

Facebook Login - Facebook Authentication and Cocoapods

Create a new application facebook login and authentication a facebook user using their iOS SDK with Cocoapods. Below are the steps in which we'll be following: First Getting Started guide from Facebook's iOS SDK Documentation Create a new iOS project Swift

Open facebook Developer Account and create new App after go to setting and click basic -> add platform ios Then add Bundle id your ios project like com.xxxx, Configuring Facebook with Bundle ID Then go ahead Download facebook sdk for ios other wise install pod file your project.
Go ahead to open terminal and go ahead your project folder.

Got create podfile -> pod init
Open podfile -> open podfile Paste ->  pod 'FBSDKCoreKit' 
               pod 'FBSDKShareKit' 
               pod 'FBSDKLoginKit' podfile and save

Then go to terminal or install podfiles -> pod Install

Enabling Facebook's Authentication Mech…

Core Data With Swift 4.0 Tutorial

Core Data - Core Data is a framework that you use to manage the data model layer objects or instance Context in your application. It provides generalized and automated data stores solutions to common tasks associated with object life cycle and object graph management, including persistence.
Completely Tutorial for Swift 4 and iOS 11. Gating Start Goto Xcode and create New iOS Project on single view. Project Name CoreDataSwift or Checked Use Core Data

On click Main.Storyboard in Interface builder click on project navigation Editor - Embed In - Navigation controller.

Then After click on Navigation ViewController and next Drag TableView in to ViewController.

Make TableView viewcontroller Outlet Delegate, DataSource and import CoreData

import UIKit import CoreData
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { overridefunc viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } overridefunc didReceiveMem…