Home » Scala language

Semicolons in Scala

Scala semicolons: Semicolons are very important in programming; tell the compiler about the end of line statement. In Scala programming, using semicolons is not compulsory. In this Scala tutorial, we will learn about Scala semicolons and sample code.
Submitted by Shivang Yadav, on July 14, 2019

Scala semicolons

A semicolon or semi-colon (;) is a punctuation mark in programming, it is used to separate multiple lines of code. It is common in major programming languages like C, C++, Java, Pascal. In modern programming languages like Python, Scala.

The semicolon is treated as the end of line statement. It treats it as the end of the expression, if not the expression can continue to the next line. But, in Scala, the end of the line is treated as the end of the expression. This means the user does not need to compulsorily use the semicolon (;) statement.


    Code with a semicolon :     var a : int = 3445; 
    Code without semicolon:     var a : int = 3445


object MyClass {
      def main(args: Array[String]) {
         println("This statement is executed with semicolon");
         println("This statement is executed without semicolon")         


This statement is executed with semicolon
This statement is executed without semicolon

Code logic:

The code here has two print statements one print statement ends with a semicolon and second without semicolon. Both lines are valid and print the given strings.


Comments and Discussions!


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

© some rights reserved.