zoukankan      html  css  js  c++  java
  • Swift学习——使用if和switch来进行条件操作,使用for,while,和do-while来进行循环(三)

    Swift学习——使用if和switch来进行条件操作,使用for,while,和do-while来进行循环


    //switch支持随意类型的数据以及各种比較操作——不不过整数以及測试相等

    //注意假设去掉default程序会报错

    let strings = "hello3"
    switch strings{
        case "hello1":
        let stringsComment = "say hello1"
        println("stringsComment is (stringsComment)")
        break
        case "hello2","hello3":
        let stringsComment = "say hello2 and hello3"
        println("stringsComment is (stringsComment)")
        break
        case let x where x.hasSuffix("hello4"):
        let stringsComment = "Is it a spicy (x)?

    " println("stringsComment is (stringsComment)") break default: let stringsComment = "say everything" println("stringsComment is (stringsComment)") }



    简单的while和do-while循环


    // while循环
    var n = 3
    while n < 100{
        n = n*2
    }
    println("n is (n)")
    
    //do-while循环
    var m = 3
    do{
        m = m*2
    }while m < 100
    
    println("m is (m)")

    打印结果

    stringsComment is say hello2 and hello3

    n is 192

    m is 192



  • 相关阅读:
    寻找两个有序数组的中位数
    JAVA设计模式(组合模式)
    excel 操作
    研究生英语-春
    cvs
    Spring课程安排
    Spring的事务管理
    在WEB项目中集成Spring
    计算机网络参考模型
    揭开5G神秘面纱
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6953581.html
Copyright © 2011-2022 走看看