Chapter 4 : Types of Comments



Types of Comments



1. Single line Comments : (//)



Single-line comments starts with // and cannot span across multiple lines.


//
//  main.swift
//  Swift Tutorials 2014-15
//
//  Created by Code2care on 15/09/14.
//  Copyright (c) 2014 Code2care. All rights reserved.
//


//This is an Example of Single line Comments in Swift

println("Hello!") // Will print Hello on the Console!



Output :

Hello!
Program ended with exit code: 0


2. Multi-line Comments. (/* */)



Multi-line comments starts with /* and ends with */ and can span across multiple lines.


//
//  main.swift
//  Swift Tutorials 2014-15
//
//  Created by Code2care on 15/09/14.
//  Copyright (c) 2014 Code2care. All rights reserved.
//


/* This
is
an
Example
of
Multi-line
Comments 
in 
Swift */

// Will print Hello on the Console!
// and  on a new line!
println("Hello!") 




Output :

Hello!
Program ended with exit code: 0


3. Shell/Perl Style single line Comments. (#)



Shell/Perl Style comments start with # and cannot span across multiple lines.


//
//  main.swift
//  Swift Tutorials 2014-15
//
//  Created by Code2care on 15/09/14.
//  Copyright (c) 2014 Code2care. All rights reserved.
//


#This is a Shell/Perl Style comments

# Will print Hello on the Console!
println("Hello!")