zoukankan      html  css  js  c++  java
  • Swift-5-流程控制

    // Playground - noun: a place where people can play
    
    import UIKit
    
    // For-In 循环
    // 1 遍历数字区间
    for index in 1...5 {
        println("(index) times 5 is (index)")
    }
    
    // 2 遍历数组
    let names = ["Anna", "Alex", "Brain", "Jack"]
    for name in names {
        println("hello, (name)")
    }
    
    // 3 遍历字典
    let numberOfLegs = ["spider" : 8, "ant" : 6, "cat" : 4]
    for (name, legCount) in numberOfLegs {
        println("(name) has (legCount) legs")
    }
    
    // 4 遍历字符
    for character in "hello" {
        println(character)
    }
    
    // For 循环
    for var index = 0; index < 3; index++ {
        println("index is (index)")
    }
    
    // While do-while
    var i = 0
    do {
        i++
    } while (i < 3)
    
    while (i < 5) {
        i++
    }
    
    // 条件语句 Conditional Statements
    var temperatureInFahrenheit = 30
    if temperatureInFahrenheit <= 32 {
        println("It's very cold")
    }
    
    switch temperatureInFahrenheit {
        case 1...20:
            println("1...20")
        case 23, 30:
            println("come here")
            fallthrough // 默认不会进入下一个判断,加上这个关键字可以让匹配直接进入下一个
        default:
            println("default")
            break // 跳出switch
    }
    
    var somePoint = (1, 1)
    switch somePoint {
        case let (x, y) where x == y:
            println("equal")
        default:
            break
    }
  • 相关阅读:
    linux转换win下乱码txt命令
    linux下vi命令大全详细版本
    ubuntu系统如何安装adb调试环境
    LeetCode136---只出现一次的数字
    微信发朋友圈--用例设计(转)
    微服务
    LeetCode1---两数之和
    python输出
    爬楼梯,N级楼梯有多少种走法?
    list数组排序---stream
  • 原文地址:https://www.cnblogs.com/liufeng24/p/4117184.html
Copyright © 2011-2022 走看看