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