Continue
The continue statement completes the current iteration of the loop statement, but does not stop the execution of the loop statement.
var sum = 0;
for var i = 0 ; i < 5 ; i++ {
if i == 4 {
continue //this ends this iteration of the loop
}
sum += i //thus, 0, 1, 2, and 3 will be added to this, but not 4
}
Break:
The break statement terminates the execution of a loop program, an if statement, or a switch statement.
var sum = 0;
for var i = 0 ; i < 5 ; i++ {
if i == 2 {
break
}
sum += i
}
fails:
The final statement causes the program to continue from one case to the switch statement in the next case.
var sum = 0
var i = 3
switch i {
case 1:
sum += i
case 2:
sum += i
case 3:
sum += i
fallthrough //allows for the next case to be evaluated
case i % 3:
sum += i
}
throw:
You use the throw statement to throw an error.
, , , - .
throw VendingMachineError.InsufficientFunds(coinsNeeded: 5)
:
return .
func myMethod(){
newMethod()
}
func newMethod(){
var sum = 0;
sum += 2;
if sum > 1 {
return
}
sum += 3;
}
.
func myFunc() {
let value = newFunc()
}
func newFunc() -> Int {
return 5
}