Swift - If-else-if Statement Last Updated : 11 Sep, 2022 Comments Improve Suggest changes Like Article Like Report In Swift, the if-else if-else condition is used to execute a block of code among multiple options. It gives a choice between more than two alternative conditions as soon as one of the conditions is true, the statement associated with that if is executed. If all conditions are false or not satisfied then the final else statement will be executed in the program. Syntax: if (condition1){ // Block of code and Statements } else if (condition2){ // Block of code and Statements } else if (condition3){ // Block of code and Statements } . . . else { // Block of code and Statements }Here, If condition1 is true, then statement 1 is executed. If condition1 is false, then it will go to else if statement and evaluate condition 2. If condition 2 is true, statement 2 will be executed. If condition 2 is false, then it will go to else if statement and evaluate condition 3 likewise so on. If neither condition is true it will move to the else part and then the final else statement will be executed. Flowchart: Example 1: Swift program illustrate the use of if-else-if statement. Swift let number = 85 if (number >= 90){ print("Grade A") } else if (number >= 75) { print("Grade B") } else if (number >= 60) { print("Grade c") } else { print("Grade D") } Output: Grade BExplanation: In the above example, first we create a variable named "number". Now using the if-else-if statement we check if the number is greater than or equal to 90, assigning grade A. Or if the number is greater than or equal to 75, assign grade B. Or if the number is greater than or equal to 60, assign grade C. So here the output will be Grade B because number = 85 which satisfies the condition "number is greater than or equal to 75". Example 2: Swift let number = 20 // Condition 1 if (number == 10){ // Print statement print("Number is 10") } // Condition 2 else if (number == 15){ // Print statement print("Number is 15") } // Condition 3 else if (number == 20){ // Print statement print("Number is 20") } else{ // Print statement print("Number is not present") } Output: Number is 20 Explanation: In the above example, we created a variable that holds an expression and we have three condition expressions: if (number == 10) : checks if number equal to 10else if (number == 15) : checks if number is equal to 15.else if (number == 20) : checks if number is equal to 20.Here, both conditions1 and condition2 are false. Hence the statement will move to condition3(condition3 is true) and statement 3 is executed. Create Quiz Comment S saptarishimondal Follow 0 Improve S saptarishimondal Follow 0 Improve Article Tags : Swift Swift-Control-Flow Explore Swift IntroductionSwift - Hello World Program2 min readSwift - Basic Syntax5 min readSwift - Keywords4 min readSwift - Literals10 min readSwift - Constants, Variables & Print function2 min readSwift - Operators8 min readSwift Data TypesSwift - Data Types5 min readSwift - Integer, Floating-Point Numbers2 min readStrings in Swift8 min readString Functions and Operators in Swift10 min readHow to Concatenate Strings in Swift?3 min readHow to Append a String to Another String in Swift?2 min readHow to Insert a Character in String at Specific Index in Swift?2 min readHow to check if a string contains another string in Swift?2 min readHow to remove a specific character from a string in Swift?2 min readData Type Conversions in Swift5 min readSwift - Convert String to Int Swift3 min readSwift Control FlowSwift - Decision Making Statements5 min readSwift - If Statement3 min readSwift - If-else Statement3 min readSwift - If-else-if Statement3 min readSwift - Nested if-else Statement4 min readSwift - Switch Statement10 min readSwift - Loops5 min readSwift - While Loop2 min readSwift - Repeat While loop3 min readSwift - For-in Loop6 min readSwift - Control Statements in Loops5 min readSwift - Break Statement6 min readSwift - Fallthrough Statement4 min readSwift - Guard Statement15 min readSwift FunctionsCalling Functions in Swift6 min readSwift Function Parameters and Return Values10 min readHow to Use Variadic Parameters in Swift?6 min readSwift - In Out Parameters4 min readSwift - Nested Function5 min readSwift - Function Overloading8 min readClosures in Swift9 min readEscaping and Non-Escaping Closures in Swift5 min readHigher-Order Functions in Swift10 min readSwift CollectionsSwift - Arrays9 min readSwift - Arrays Properties4 min readSwift - How to Store Values in Arrays?4 min readHow to Remove the last element from an Array in Swift?4 min readHow to Remove the First element from an Array in Swift?4 min readHow to count the elements of an Array in Swift?2 min readHow to Reverse an Array in Swift?3 min readSwift Array joined() function3 min readHow to check if the array contains a given element in Swift?3 min readSorting an Array in Swift5 min readHow to Swap Array items in Swift?2 min readHow to check if an array is empty in Swift?2 min readSwift - Sets15+ min readSwift - Set Operations9 min readHow to remove first element from the Set in Swift?2 min readHow to remove all the elements from the Set in Swift?2 min readHow to check if the set contains a given element in Swift?3 min readHow to count the elements of a Set in Swift?2 min readSorting a Set in Swift4 min readHow to check if a set is empty in Swift?2 min readHow to shuffle the elements of a set in Swift?2 min readSwift - Difference Between Sets and Arrays3 min readSwift - Dictionary9 min readSwift - Tuples3 min readSwift - Iterate Arrays and Dictionaries6 min readSwift OOPsSwift Structures7 min readSwift - Properties and its Different Types13 min readSwift - Methods5 min readSwift - Difference Between Function and Method4 min readSwift - Deinitialization and How its Works?4 min readTypecasting in Swift7 min readRepeating Timers in Swift4 min readNon Repeating Timers in Swift7 min readDifference between Repeating and Non-Repeating timers in Swift4 min readOptional Chaining in Swift9 min readSingleton Class in Swift4 min readSwift Additional TopicsSwift - Error Handling2 min readDifference between Try, Try?, and Try! in Swift4 min readSwift - Typealias7 min readImportant Points to Know About Java and Swift3 min readDifference between Swift Structures and C Structure4 min readHow to Build and Publish SCADE Apps to Apple and Google Stores?11 min read6 Best iOS Project Ideas For Beginners8 min read Like