Swift switch statement


Release date:2023-11-25 Update date:2023-12-08 Editor:admin View counts:244

Label:

Swift switch statement

The switch statement allows you to test when a variable is equal to multiplevalues. In the Swift language, as long as the match to case statement,the entire switch statement is executed.

Grammar

The syntax of switch statements in the Swift language:

switch expression {
   case expression1  :
      statement(s)
      fallthrough /* optional */
   case expression2, expression3  :
      statement(s)
      fallthrough /* optional */

   default : /* optional */
      statement(s);
}

It is generally not used in switch statements fallthrough statement.

We need to pay attention to this. case if you do not use the fallthrough statement, the current case statement, the switch terminates and the control flow jumps to the next line after the switch statement.

If used fallthrough statement, the execution of the case or default statement that is executed regardless of whether the condition is met or not.

Powered by TorCMS (https://github.com/bukun/TorCMS).