Swift guard Statement

In this tutorial you will learn about the Swift guard Statement and its application with practical example.

Swift guard Statement

In Swift, the guard statement enable us to transfer program control out of a scope on specified condition. The guard statements are very similar to swift if statement, but unlike if, the guard statement allows block of code to be executed only when test expression returns False.

Syntax:-

Here, Condition is a Boolean expression that results in either True or False, if it results in False then statements inside else body are executed, if it results in True then statements inside else body are skipped and control jumps to next statement.The else body must contain a return, break, continue or throw in order to exit from the scope.

Example :-

Output:-

swift_guard_statement

In this tutorial we have learn about the Swift guard Statement and its application with practical example. I hope you will like this tutorial.