swift if语句,switch语句,元组,函数
//// main.swift// L00flow//// Created by hins on 16/10/26.// copyright © 2016年 hins. All rights reserved.//import Foundationprint("Hello,World!")var str = "Hello";for(var i=0;i<5;i=i+1){ print(i)}//流程控制//=======if语句for i in 1...10{ if(i%2==0){ print(i); } if(i != 3){ print("ccccc") } if(i>5 && i<=7){ print("jjjj") }else{ print("ttttt") }}//========switch语句var index = 3;switch (index){case 1 : print(index); break;case 2 : print(index); break;case 3 : print(index); break;default: break; }//=============switch语句var valChar = "bc";switch (valChar){case "a" : print(valChar); break;case "b" : print(valChar); break;case "bc" : print(valChar); break;default: break; }//==========元组(区间)let somePoint = (1,1)switch somePoint {case (0,0): print("(0,0) is at the origin")case (_,0): print("(\(somePoint.0),0) is on the x-axis")case (0,_): print("(0,\(somePoint.1)) is on the y-axis")case (-2...2,-2...2): print("(\(somePoint.0),\(somePoint.1)) is insIDe the Box")default: print("(\(somePoint.0),\(somePoint.1)) is outsIDe of the Box")}// prints "(1,1) is insIDe the Box"//============函数//无返回值func getString(name:String){ print("wwwwww,\(name)")}//调用getString("xuan");//有返回值func getValueBB(name:String,age:Int) -> String { print(name); return name;}//调用 (有些参数提示要带标签 如:age:23,否则报错)var a2 = getValueBB("nununu",age:23);print(a2)func getNums() -> (Int,Int){ print("hello"); return (2,3);}//调用let (a,b) = getNums();print(b);var fun22 = getValueBB;//函数赋值给变量_ = fun22("test",age:45);//_ 下划线表示不接收返回值//函数闭包 (函数中包含函数)func namefunc(){ print("函数里面有一个函数"); func namefunc333(){ print("hahaha") }}总结
以上是内存溢出为你收集整理的swift 的if语句,switch语句,元组,函数全部内容,希望文章能够帮你解决swift 的if语句,switch语句,元组,函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)