In this article, I've summarized the repetitive sentences that are often used in Swift.
This article was written with reference to the following information.
-Introduction to Swift Practice
Control syntax for accessing elements of type (Array, Dittionary, etc.) that conform to the Sequence protocol. Repeat as many times as the number of elements while passing each element to the executable statement in sequence. In the executable statement, you can access the element through a constant with the name specified as the element name.
Statements that are repeatedly executed element by element
}
When enumerating elements of Array
A control syntax that keeps repeating as long as the conditional expression holds. The while statement consists of a conditional expression and a statement that is repeatedly executed. The conditional expression of the while statement must return a Bool type like the if statement and for-in statement. The conditional expression is evaluated every time before the execution statement is executed. If the result is true, the iteration is continued, if false, the iteration is stopped, and the processing of the entire while statement is terminated.
Statements that are repeatedly executed while the conditional expression is satisfied
}
Since the while statement is usually evaluated before execution, it may not be processed even once in some cases. However, if the repeat-while statement is used, the conditional expression is evaluated after the executable statement, so processing is always performed once regardless of the success or failure of the condition.
A statement that is always processed once and then repeatedly executed as long as the conditional expression is satisfied
}while conditional expression
Suspends the execution statement and ends the entire repeating statement. It is used when there is no need to repeat it any more.
After suspending the execution statement, the subsequent repetition is continued. Use this when you want to skip processing only in a specific scene. Use the continue statement only with the continue keyword or in combination with the label.
Control targets can be specified using labels in break statements and continue statements. It is used when you want to exit once from a nested repetition. To make a repeating statement visible by label, add the label name: before the repeating statement.
Repeated sentence
Specify the target iteration statement by adding the label name after the break and continue keywords.