Swift If Statement describes how you can perform actions based on certain condition (boolean value). In this article, we will explore the benefits of guard statement over if statement to control the program flow and write more simpler and clean code.
The switch statement is also a variety of Swift control statement e.g.if-else, guard etc., that performs different actions based on different conditions.
The beauty of switch statement is, it can compare a value with several possible matching patterns. Therefore, it can be used as a substitute for long if..else..if ladders while matching complex pattern.
Operator precedence is a collection of rules used in order to evaluate a given mathematical expression. When there are several operators used in a single expression, each part is evaluated in a certain order called as operator precedence. Certain operators have higher priority than others which affects how an expression is evaluated.
In programming, you may want to perform different actions based upon the specified condition is true or false (which is known only during the run time). For such cases, control flow statements are used.
In the previous article, we learned about for-in loop to run a set of tasks for a certain number of times. In this article, you will learn to use while and repeat..while as an alternative of for-in loop when the number of iteration is unknown.
A while loop executes a set of statements until a condition becomes false. These kinds of loops are best used when the number of iterations is not known before the first iteration begins. Swift provides two kinds of while loops: