Scala分号 (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.
分号或分号 ( ; )是编程中的标点符号,用于分隔多行代码。 它在C,C ++,Java,Pascal等主要编程语言中很常见。 在现代编程语言(如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.
分号被视为行语句的结尾 。 它将其视为表达式的末尾 ,否则表达式可以继续到下一行。 但是,在Scala中,该行的结尾被视为expression的结尾 。 这意味着用户不需要强制使用分号 ( ; )语句。
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.
此处的代码有两个打印语句,一个打印语句以分号结尾,第二个不带分号。 这两行均有效,并打印给定的字符串。
翻译自: https://www.includehelp.com/scala/semicolons-in-scala.aspx