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.
Syntax:
Code with a semicolon : var a : int = 3445;
Code without semicolon: var a : int = 3445
Example:
object MyClass {
def main(args: Array[String]) {
println("This statement is executed with semicolon");
println("This statement is executed without semicolon")
}
}
Output
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.
TOP Interview Coding Problems/Challenges