swift控制流(代码片段)

author author     2023-01-19     335

关键词:

var todo: [String] = ["Finish Collection Course", "BUy Groceries", "Respond to emails", "Pick up dry cleaning", "Order books online", "Mow the lawn"]

for task in todo 
    print(task)


//  Ranges

for number in 1...10 
    print("\(number) times 5 is equal to \(number*5)")


// While Loop

var x = 0

while x <= 20 
    print(x)
    x += 1


var index = 0

while index < todo.count 
    print(todo[index])
    index += 1


// Repeat While

var counter = 1

while counter < 1 
    print("I'm inside the while loop")
    counter += 1


repeat 
    print("I'm inside the repeat loop")
    counter += 1
 while counter < 1

// If Statements

var temperature = 9


if temperature < 12 
    print("It's getting cold. Let's get taht jacket out.")
 else if temperature < 18 
    print("It's getting chilly. I recommend wearing a light sweater.")
 else 
    print("It feels great outside! A t-shirt will do.")


// Logical Operators

if temperature > 7 && temperature < 12 
    print("Might want to wear a scarf with that jacket")


var isRaining = true
var isSnowing = false

if isRaining || isSnowing 
    print("Get out those boots!")


if !isRaining 
    print("Yay the sun is out")


if isRaining && isSnowing && temperature < 2 
    print("Put some gloves on")


if (isRaining || isSnowing) && temperature < 2 
    print("Definitely get the leather gloves out!")


// Switch Statement

let airportCodes = ["LGA", "LHR", "CDG", "HKG", "DXB", "LGW", "JFK", "ORY"]

for airportCode in airportCodes 
    switch airportCode 
    case "LGA", "JFK": print("New York")
    case "LHR", "LGW": print("London")
    case "CDG", "ORY": print("Paris")
    case "HKG": print("Hong Kong")
    default: print("I don't know which city that airport is in!")
    


import GameKit

let randomTemperature = GKRandomSource.sharedRandom().nextInt(upperBound: 150)

switch randomTemperature 
case 0..<32: print("Forget clothes, you are basically a popsicle")
case 32..<45: print("It's quite cold. You'll need a jacket")
case 45..<70: print("It's a bit chilly. I recommend wearing a light sweater")
case 70...100: print("It's quite hot! T-shirt weather!")
default: print("Don't even bother to go out!")

swift语句参考!(代码片段)

在Swift中,有两种类型的语句:简单语句和控制流语句。简单语句是最常见的,用于构造表达式和声明。控制流语句则用于控制程序执行的流程,Swift中有三种类型的控制流语句:循环语句、分支语句和控制传... 查看详情

swift学习-06--控制流

//控制流//swift提供了多种控制流结构,包括可以多次执行的while循环,基于特定条件选择执行不同分支的if,guard和switch语句,还有控制流程跳转到其它代码位置的break和continue语句//swift还提供了了for-in循环,用来更简单地遍历数组(array),... 查看详情

swift--控制流

Swift中提供了一系列的控流状态,其中包括可以多次执行相同任务的while循环、根据不同的条件执行不同分支的ifguardswitch等语句,以及例如用break和continue来选择是否跳出循环执行其他的代码。 Swift也提供对数组、字典、范围... 查看详情

swift菜鸟入门视频教程-05-控制流

...够在这里留言。 主要内容: For循环 While循环 条件语句 控制转移语句(ControlTransferStatements) 视频地址: 百度网盘:http://pan.baidu.com/s/1hq44BFe 土豆:http://www.tudou.com/programs/view/R629qicZGeo/ 源代码: 查看详情

8.swift教程翻译系列——控制流之条件

3.条件语句常常会须要依据不同的情况来运行不同的代码。你可能想要在错误发生的时候运行一段额外的代码,或者当某个值变得太高或者太低的时候给他输出出来。要实现这些需求,你能够使用条件分支。Swift提供两种方式... 查看详情

swift控制流程迅速(代码片段)

查看详情

swift警报控制器(代码片段)

查看详情

swift自定义分段控制(代码片段)

查看详情

swift应用程序的swift控制器(代码片段)

查看详情

sqlmssql控制流-转到(代码片段)

查看详情

sqlmssql控制流-同时(代码片段)

查看详情

swift表格导航控制器(代码片段)

查看详情

The Swift Programming Language Book Chapter Section 控制流实验 3

】TheSwiftProgrammingLanguageBookChapterSection控制流实验3【英文标题】:TheSwiftProgrammingLanguageBookChapterSectiononControlFlowExperiment3【发布时间】:2014-06-0322:02:28【问题描述】:我正在阅读本书的第一章,但无法弄清楚实验:添加另一个变量... 查看详情

swift来自xib的控制器(代码片段)

查看详情

swift后父控制器时调用函数(代码片段)

查看详情

javascriptnode.js模式:异步控制流(代码片段)

查看详情

swift以编程方式设置初始控制器(代码片段)

查看详情

swift3.0p1语法指南——控制流

原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html#//apple_ref/doc/uid/TP40014097-CH9-ID1201、For循环(1)forin使用for-in来遍历一个集合里 查看详情