Swiftのif, for while


スポンサーリンク

//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"


//if
let score = 70

if score>=80 {
    print ("合格です!")
} else {
    print("不合格〜!")
}

print("\(score)点でした。")


//switch
let color = "blue"

switch color {
case "red":
    print("赤やね!")

case "green":
    print("緑やね!")
    
case "pink","yellow":
    print("ピンクか黄色だね!")
    
case "blue":
    print("青やね")
default:
    print("お前の色はなんだーーー!")
}

//tupple
let data = (1000,100,10)
let (sen,hyaku,jyu) = data
let hoge = sen + hyaku
print(hoge)

//label tupple
let user = (name:"yoshida", age:20)
print(user.name)


//for
for num in 1...10 {
    print(num, terminator: ",")
}

for _ in 1...15 {
    let num = arc4random_uniform(100)
    print(num, terminator: ",")
}


let numList = [1,2,3,4,5,6]
var sum = 0
for num in numList {
    sum += num
}

print("合計: \(sum)")


for (var i=0; i<5;i++) {
    let v = i*2
    print(v)
}