Basic SWIFT data types and loops

Source: Internet
Author: User

This document describes the variables, data types, and cycles of the SWIFT language.

1. Constant variable

VaR myvariable = 42 // variable
Myvariable = 50
Let myconstant = 42 // constant


2. Indicate the variable type.


Let explicitdouble: Double = 70


3 arrays and dictionaries


VaR shoppinglist = ["catfish", "water", "tulips", "blue paint"]
Shoppinglist [1] = "bottle of water"

VaR occupations = [
"Malcolm": "captain", // The value is followed by the key.
"Kaylee": "mechanic ",
]
Occupations ["Jayne"] = "Public Relations"


4. Create an array and dictionary for initialization.


Let emptyarray = string [] ()
Let emptydictionary = dictionary <string, float> ()

5. Add an array


VaR emptyarry = string [] ()
Emptyarry. append ("DFD ")

6. For Loop


Let SSS = [43,554, 12,434,]
For I in 0 .. 4 {
Print ("(I) = (SSS [I])");
Print ("N ");
}
For I in SSS {
Print (I );
Print ("N ");
}


7 Switch

Let vegetable = "red pepper"
Switch vegetable {
Case "Celery ":
Let vegetablecomment = "add some raisins and make ants on a log ."
Case "cucumber", "watercress ":
Let vegetablecomment = "That wocould make a good tea sandwich ."
Case Let X where X. hassuffix ("Pepper "):
Let vegetablecomment = "Is it a spicy (x )? "Fallthrough
Default:
Let vegetablecomment = "Everything tastes good in soup ."
}

SELF: http://www.phperz.com/article/14/0802/15200.html

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.