iOS_一些基礎程式語法_第一階段
第一階段.程式溫故
//
// ViewController.swift
// ex_Array
//
// Created by stu_11 on 2017/4/14.
// Copyright © 2017年 mcu. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("========變數型態及轉型var,let,const=========")//Ctrl + Space 控制 輸入法 變成 注音or英文
print("========var可添加、可改變==========")
var num = 13
var num2 = 24.65
var num3 = "Apple"
print("原本的值(int):" , num)
print("原本的值(double):" , num2)
print("原本的值(string):" , num3)
num += 2
num2 += 0.3
num3 += " Banana"
print("修改後的值(int)加2後:" , num)//這裡我發現在MAC電腦上執行中文輸入的時候 會把 '加' 相關讀音 的 表情符號 '家' 一同打印
print("修改後的值(double)加0.3後:" , num2)
print("修改後的值(string)加入Banana字串之後:" , num3)
print("========let不可添加、不可改變==========")
let numlet = 13
let num2let = 24.65
let num3let = "Beef"
print("原本的值(int):" , numlet)
print("原本的值(double):" , num2let)
print("原本的值(string):" , num3let)
/*
numlet += 3
num2let += 4.5
num3let += " Noodle"
print("原本的值(int):" , numlet)
print("原本的值(double):" , num2let)
print("原本的值(string):" , num3let)
*/
print("========casting強制轉型=Int(變數名)、Double(變數名)、Float(變數名)=========")
var weight = 67.54
print("轉型前")
print(weight)
var weightInt = Int(weight)
print("轉型後(轉Int後)")
print(weightInt)
print("=======表情符號Mac電腦: Ctrl+Cmd+Space=======")
print("🙀 👻🎃")
print("========陣列學習_成員列印=========")
var recipes = ["Egg Benedict" , "Mushroom Risotto" , "Full Breakfast" , "Hamburger"]
//print(recipes[1])
//swift3 for loop method1
for i in 0..<4{
print("index = \(i)")
}
//swift3 之後 沒有 println 了
print("================================")
//swift for loop method2
//打印 陣列中的元素內容成員
//iterate through an array
for recipItem in recipes{
print(recipItem)
}
print("==========if...else...==========")
var bookPrice = 1000
if bookPrice >= 999{
print("Hey!!! the book is too expensive!")
}
else{
print("Okay , I can affort it")
}
print("==========switch...case...==========")
print("Switch...Case...____可處理字串")
/*
switch recipes{
case "Egg Benedict":
print("Let's Cook!!")
case "Mushroom Risotto":
print("Hmm.. let me think about it")
case "Hamburger":
print("Love it!!")
default:
print("Anything Else")
}
*/
var speed = 65
switch speed{
case 0:
print("Stop")
case 0...40:
print("Slow")
case 41...70:
print("Normal")
case 71...101:
print("Fast")
default:
print("Not Classified Yet!!!")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
留言
張貼留言