Swift Comments | Types of comments in Swift

Here, we have discussed about what is Swift comments, types of Swift comments and how to use Swift comments. Swift comments are those portions of....

Welcome to the another most interactive article on Swift Programing langauge.

Swift Comments | Types of comments in Swift | Swift Multiline comment

In this article we will learn about what is Swift comments, types of Swift comments and how to use Swift comments. So without wasting any time let's dive in!!

What is Swift Comments? 

Swift comments are those portions of program which are completely ignored and not executed by the Swift interpreter and compiler. Most of programmer's use comments as a note or reminder for oneself. 

In other words we can say that, Swift comments are like a hints that we can use to make our coding more understandable.

Types of Comments in Swift

In Swift Programing langauge, there are two types of comments or we can say two ways to add comments in Swift;

Single Line Comment

Any text which begins with two forward slashes // is said to be Swift single line comment.

Swift Single Line Comment Example;

// create a variable 

var name = "Welcome to Answersjet"

// print the value

print(name)

Output

Welcome to Answersjet

Here, both // create a variable and // print the value are the example of Single Line Comment in Swift.

Multi Line comment

Any text which begins with forward slash followed by an asterisk and ends with asterisk followed by forward slash is said to be Swift multi line comment.

Swift Multi line comment Example;

/* create a variable

to store the pension of Government employees

*/

var pension = 7000

print(pension)

Output

7000

Here /* create a variable to store the pension of Government employees/* is an example of Multi line comment in Swift.

Conclusion

Above we have discussed about what is Swift comments, types of Swift comments and how to use Swift comments. Swift comments are those portions of program which are completely ignored and not executed by the Swift interpreter and compiler. In Swift Programing langauge, there are two types of comments i.e., single line and multi line comments.