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