Slow product Scala 1 custom control structure

Source: Internet
Author: User

The common control structures are if, for, and while.

Control the structure function?

is the function a control structure?

At the CPU level, there are some jump statements.

In other languages, control statements are more basic. The function is composed of control statements.

In Scala, functions are more fundamental, and closures created with functions can implement all control structures.

(Closures are a big topic, word: Closures can say we see traces of wind)


The implementation of the while expression

def wh (p: = = Boolean) (s: = = Unit) {if (p) {s; WH (P) (s)}} var i = 0;  var sum = 0; WH (i <) {i + = 1 sum + = i} println (sum)


You can see that the IF expression is more basic because the while statement depends on it. So how do you implement an if expression?


(Note: The statement has no return value, the expression has a return value, Scala if,while is an expression)

Slow product Scala 1 custom control structure

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.