Home » Scala language

Comments in Scala

Scala comments: Comments are a very important part of programming. In Scala comments are Java-like. In this Scala tutorial on comments, we will learn how to use comments with working code.
Submitted by Shivang Yadav, on July 14, 2019

Scala comments

Comments are things that are readable by the programmer. They are added to the code to add an explanation about the source code. Commenting on a program to make it easier to understand by the programmer.

In Scala also comments are available. The comments in Scala are same as C++, Java and many other popular programming languages.

There are two types of comments that can be added to a program:

  1. Single-line comment
  2. Multiline Comment

1) Single line comment

It is the comment that has a span of an only single line. The line in which comment is started is commented.

Syntax:

    // Single line code to be commented...

2) Multiline comment

A multiline comment can span up to many lines based on its end literal. A multiline comment starts and ends with a literal and all the code inside that literal is treated as a comment.

Syntax:

    /* 
    Multiline
    Code to be commented 
    */

Example for Scala comments

object MyClass {
      def main(args: Array[String]) {
         //printing Hello world! - this is single line comment
         print("Hello world!");
         
         /* 
         This is multiline comment - 
         Here, we are printing Hi friends!
         */
         print("Hi friends!");
      }
   }

Output

Hello world!Hi friends!





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.