Google News
logo
Swift - Interview Questions
Explain the GUARD statement. What is the benefit of using the GUARD statement in Swift?
It is used to shift the program control out of the scope if there is scope when one or more condition is not met. It is also called as early exit and similar to the ‘if statement’.  By using the Guard statement, we can avoid the pyramid of doom.
 
Example :
guard expression else {

//statements

//must contain a control statement:return, break, continue or throw.

}
Advertisement