zoukankan      html  css  js  c++  java
  • Swift

    //: Playground - noun: a place where people can play
    
    import UIKit
    
    // fallthrough
    // fallthrough会在当前case执行完之后继续下一个case
    // 如果在下一个case中声明了变量, 则不能使用fallthrough
    var coordinate = (1, 0)
    switch coordinate {
    case (0, 0):
        print("It's at origin!")
        fallthrough
    case (_, 0):
        print("((coordinate.0), 0) is on the x-axis.")
        fallthrough
    case (0, _):
        print("(0, (coordinate.1)) is on the y-axis.")
        fallthrough
    case (-2...2, 0...2):
        print("the coordinate is ((coordinate.0), (coordinate.1))")
    default:
        print("((coordinate.0), (coordinate.1)) is just an ordinary coordinate")
    }
    
    // break
    for var i = 0; i < 10; i++ {
        print(i)
        for var j = 0; j < 10; j++ {
            print(j)
            if i + j == 10 {
                print(i + j)
                break   // 跳出break所在的循环体
            }
        }
    }
    
    
    // continue
    var str = "askdjfskldjfdifjhget,n,mcnmvxcvawperiuzxncv,."
    var num = 0;
    for string in str.characters {
        switch string {
            case ",", ".":
                num++
            default:
                continue;
        }
    }
    
    // 初始化二维数组
    var board = Array<Array<Int>>()
    for i in 0..<10 {
        // count: 数组初始化后的元素个数 repeatedValue: 数组的元素的值
        board.append(Array(count: 10, repeatedValue: 0))
    }
    
    let randx = Int(arc4random()%10)
    let randy = Int(arc4random()%10)
    board[randx][randy] = 1
    board
    
    // mainFor用于标记某个循环, 有了标记, break就可以直接跳出某个指定的循环了. eg:
    var i = 0, j = 0
    mainFor:for i = 0; i < 10; i++ {   // mainFor这个标记是可以自定义的
        for j = 0; j < 10; j++ {
            if board[i][j] == 1 {
                break mainFor
            }
        }
    }
    
    print("board[(i)][(j)] = 1")
    

      

  • 相关阅读:
    「笔记」高斯消元
    函数库
    数学公式杂记
    CF1290E Cartesian Tree
    洛谷 P4027 [NOI2007] 货币兑换
    审计ThinkCMF框架任意内容包含漏洞与复现
    PHP代码审计笔记(基础篇)--命令执行漏洞
    某校园缴费平台通用0day偶然发现之路
    【转】教育src挖掘经验
    近期学习文章的整理(超级干货总结分享)
  • 原文地址:https://www.cnblogs.com/Rinpe/p/5051845.html
Copyright © 2011-2022 走看看