2014/06/08

Swift for n in range、while and do while

..:n到m-1
...:n到m
while:前置判斷
do while:後置判斷


//
//  main.swift
//  test
//
//  Created by CYFang on 6/6/14.
//  Copyright (c) 2014 CYFang. All rights reserved.
//

println("從n走訪m-1")
for index in 1..11{
    print("\(index) ")
}


println("\n\n從n走訪m")
for index in 1...11{
    print("\(index) ")
}


println("\n\nWhile")
var min = 0

while min < 10{
    min++
    print("\(min) ")
}

println("\n\nDo while")
var max = 10
do{
    println(max)
    max++
}while max < min


執行結果: