//
Main.swift
//02- Statement
//
Created by Wanghy on 15/8/9.
//Copyright (c) years Wanghy. All rights reserved.
//
Import Foundation
1.
// flow of control code using branch loops
// Branch: If If - Else Switch
// Loop: for and do - while for - inch
// true or false: with BOOL judging the true and false, the value is true and the false
//2. except Do - while and the Switch the other is basically the same, the difference is parentheses can be omitted, and curly braces cannot be omitted. For example: if (1<2){print (" I was printed ")}
If1<2
{
println ("1<2")
}
Else {
println ("1<2")
}
//3. constants can only be defined once. var-guided variables can be arbitrarily modified and assigned
var Num: Int = - ;
Num = at ;
4.
//switch You have to put all the possibilities in Case the. Multiple values can be shared one at a time, separated by commas. To have a default
//5. Looping Statements . in the 2.0 not in Do-while loops. Instead, the repeat- while loop , do in 2.0 is used as exception handling ( Do - Catch ).
// Cyclic request 1-100 and the
var sum = 0
var i = 1
while I<=
{
sum + =I+ +
}
println (sum)
//do Loops
var sum1 = 0 , j= 1
Do {
sum1 + =J+ +
} while J <=
println (SUM1)
//for Loops , operators must be separated from curly braces.
var sum3 = 0 , k= 1
for ; k <= - ; I ++ {
sum3 + +k+ +
}
println (sum3)
//for in Loops
var array = [1,2,3,4, 5]
var z:int8 = 1;
for Temp inch Array
{
if (temp! =1 && temp! = 5)
{
println (temp)
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
swift-02 Control of Code flow