Scala series: control structures and functions

Source: Internet
Author: User

In Java, expressions represent values, and statements represent execution actions. For example, expression 1 + 1 indicates the value, and thread. Start () indicates the execution action.

All Syntax structures have values, even if unit is not used.

 

If/else statement

Has a value, which is the value of the expression following if or else.

Example: Val S = If (x> 0) 1 else 0;

Equivalent to VaR S: Int = 0; If (x> 0) S = 1 else S = 0;

Val S2 = If (x> 0) "string" else 1;

S2 is of any type

Val S3 = If (x> 0) 1;

The S3 type is also any, but when x <= 0, the S3 value is unit, and the unit class indicates "no useful value", which is written ()

No switch statement

 

 

--

Scala series: control structures and functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.