HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Conditional statements through one or more set conditions to execute the program, execute the statement specified condition is true, execute additional statement specified condition is false.
The following figure can be a simple understanding of the execution of the conditional statement:
Swift provides the following types of conditional statements:
Statements | description |
---|---|
if statement | if statement consists ofa Boolean expression and one or more execution statements. |
if /en. else statement | You can have an optionalelse statement if statement,elsestatementexecutes the Boolean expression is false. |
You can have an optionalelse if after if/en. elsestatement,else if /en. else statement is often used to determine a number of conditions. | |
Embedded if statements | You can be embeddedif the ifstatement orelse iforelse ifthe. |
switch statement allows a variable equal to a plurality of test value. |
We have already explained in previous chapters of theconditional operator:?, Can be used instead if /en. elsestatement. Its general form is as follows:
Exp1 ? Exp2 : Exp3;
Wherein, Exp1, Exp2 and Exp3 expression. Please note that the use of the colon and location.
? Exp1 value of the expression is determined. If Exp1 is true, then the calculated value Exp2, the result is the entire? Expression. If Exp1 is false, then the calculated value Exp3, the result is the entire? Expression.