Swift Learning-operators

Source: Internet
Author: User

Knowledge Points:

    1. swift range Operator: < {means [x, y], that is, greater than or equal to X, less than y}, ... {means [x, Y], which is greater than or equal to X, less than or equal to Y} (primarily for the For loop)
    2. swift overflow operator ( Span style= "color: #E53333;" > Note: is provided for integral type Calculation ): &+, &-, &*, &/, &%
    3. swift supports n to n assignment
    4. swift assignment is no return value
    5. Span style= "line-height:1.5;font-size:12.5px;" >% in Swift is called the "redundancy Operator", and the positive and negative of the remainder result is the same as the positive or negative of the left value
    6. swift% Floating-point calculations are also supported
    7. bool type is similar to Boolean in Java, There are only two values of true and False
    8. if must be of type bool
Example code:

: Playground-noun:a place where people can playimport uikit//the newly added operator//range operator//in Swift < {means [x, y], that is, greater than or equal to X, less than y}, ... {means [x, Y], which is greater than or equal to X, less than or equal to Y} (mainly used for the For loop)//overflow operator//&+, &-, &*, &/, &%//1, Swift supports n assignment to n = (x, y) = (1, 2)  //That is, X is assigned a value of 1,y is assigned to 2, and both constants//2, Swift Assignment is no return value//The following code is wrong, because x = y does not return the corresponding value//if (x = y) {}//3,% in Swift is called "redundancy operator" 9 4
   //1-9% 4   // -19%-4   //1-9%-4  // -1//the positive or negative value of the residual result is the same as the positive or negative of the left number//Swift% also supports the calculation of floating-point numbers 8 2.5  //0.5//4, BOOL class Type is similar to a Boolean type in Java, only two values of true and false//in C are true, and in Swift there is no such concept//if the condition must be a value of type bool//The following error//if (1) {}//the correct if ( true) {    println ("conditional")}//5, scope operator,: < and ... for i in 0..<5 {    println (i)}//Output 0 to 4for I in 0...5 {    println (i)}//Output 0 to 5//6, Swift provides 5 &am for integral type calculation p; The opening overflow operator, which can be flexibly processed for values beyond the range of values//NOTE: Here is a let n = uint8.maxlet m = n &+ 1let n1 = Uint8.minlet M1 = N1 &-1 for integral type calculation


Swift Learning-operators

Related Article

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.