Swift
fallthrough
statement let
case
subsequent statements continue to run sequentially, regardless of whether the conditions are met or not.
The switch in Swift is not from the previous
case
the branch falls intothe next
case
in the branch. As long as the first match
case
the branch completes the statement it needs to execute, the entire
switch
the code block completes its execution.
Note: in most languages Swift Generally in The following examples are not used When the above code is compiled and executed, it produces the following results: The following examples use the When the above code is compiled and executed, it produces the following results:
switch
in the sentence block
case
keep up with it
break
otherwise,
case
subsequent statements are run sequentially, but in the Swift language, they are not executed by default
switch
and it will stop. If you want to let in Swift
case
if the subsequent statements continue to run in order, you need to use the
fallthrough
statement. 9.23.1. Grammar #
fallthrough
the syntax format of the statement is as follows:fallthrough
switch
statement does not use the
fallthrough
statement. 9.23.2. Example 1 #
fallthrough
statement:import Cocoa
var index = 10
switch index {
case 100 :
print( "The value of index is 100")
case 10,15 :
print( "The value of index is 10 or 15")
case 5 :
print( "iThe value of index is 5")
default :
print( "default case")
}
The value of index is 10 or 15
9.23.3. Example 2 #
fallthrough
statement:import Cocoa
var index = 10
switch index {
case 100 :
print( "The value of index is 100")
fallthrough
case 10,15 :
print( "The value of index is 10 or 15")
fallthrough
case 5 :
print( "The value of index is 5")
default :
print( "default case")
}
The value of index is 10 or 15
The value of index is 5