Learn Swift Together / Condition Structures And Loops
Hello everyone, in this article we will learn Comparison Structures and Loops for Swift Programming Langue.
If you are Beginner for programming, this article maybe not for you.
Learn about this series of articles.
Condition Structures
If - Else
The use of if and else is the same in swift programming language as in every programming language.
If the statement given in the condition structure of the if block is true, the block works, otherwise the else block works.
Multiple Condition structures
An expression can have more than one conditional state. There is more than one way for this ;
A. if-else if -else
B. Switch-Case-Default
Limits in switch :
Loops
For In
You use the For-In loop to iterate over a sequence, such as items in an array, ranges of numbers, or characters in a string.
For in Stride
You can specify the start, end, and ascending or descending rule of a loop.
While
A while loop performs a set of statements until a condition becomes false. These kinds of loops are best used when the number of iterations isn’t known before the first iteration begins.
Swift provides two kinds of while loops ;
A- While
It checks the status before the loop returns.
B. Repeat-While
Checks the status at the end of each turn of the loop. So the block will run at least once, even if the condition is false.
We come to the end of the article. See you in the next article :)