1、取消传统的For循环

传统的for,在swift 3.0 被取消

i++/++i在swift 3.0 被取消

i += 1代替

for var i = 0;i<10;i +=1 {

}

2、Swift 对语法要求严格,尤其是空格

/*

'空格大法' Swift 对语法要求严格,尤其是空格

@property (nonatomic, copy) NSString* name;

@property (nonatomic, copy) NSString * name;

*/

  //变量i在(0,5)循环

for i in 0..<5 {

print(i)

}

//变量i在[0,5]循环

for i in 0...5{

print(i)

}

//提示:范围定义是一个固定的格式,一定注意空格

let r1 = 0..<5

print(r1)

print("--------")

let r2 = 0...5

print(r2)

//Swift 2.0 输出格式0..<5  0..<6

//Swift 3.0 输出格式0..<5  0...5

3、反序遍历

  //Swift 3.0 (0..<10).reversed()

for i in (0..<10).reverse(){

print(i)

}

Swift-取消传统For循环的更多相关文章

  1. Swift流程控制之循环语句和判断语句详解

    Swift提供了所有c类语言的控制流结构.包括for和while循环来执行一个任务多次:if和switch语句来执行确定的条件下不同的分支的代码:break和continue关键字能将运行流程转到你代 ...

  2. iOS -Swift 3.0 -for(循环语句用法)

    // // ViewController.swift // Swift-循环语句 // // Created by luorende on 16/12/08. // Copyright © 2016年 ...

  3. Swift中的for循环基本使用

    OC中的for循环写法: ;i < ;i++) { NSLog(@"i=%zd",i); } Swift中的for循环写法: let a = ; ..< a { pri ...

  4. Effective Java 第三版——58. for-each循环优于传统for循环

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  5. swift闭包中解决循环引用的问题

    swift中可以通过三种方法解决循环引用的问题 利用类似oc方法解决循环引用weak var weakSelf = self weak var weakSelf = self loadData = { ...

  6. swift 取消UIButton选中高亮状态

    objc可以用通过重写setHighlighted方法来达到当按钮选中时的高亮状态 -(void)setHighlighted:(BOOL)highlighted{ } swift中取消高亮状态 ov ...

  7. swift中闭包的循环引用

    首先我们先创造一个循环引用 var nameB:(()->())? override func viewDidLoad() { super.viewDidLoad() let bu = UIBu ...

  8. swift 2.0 语法 循环

    //: Playground - noun: a place where people can play import UIKit /*: for循环 * 基本用法和OC一致 * 条件表达式必须是bo ...

  9. [Swift]LeetCode457. 环形数组循环 | Circular Array Loop

    You are given an array of positive and negative integers. If a number n at an index is positive, the ...

随机推荐

  1. (Delphi)第一个Windows 32 API的窗口程序

    program Project1; uses Winapi.Windows, Winapi.messages; {$R *.res} const className = 'MyDelphiWindow ...

  2. [SinGuLaRiTy] 2017 百度之星程序设计大赛-资格赛

    [SinGuLaRiTy-1034] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 度度熊保护村庄  Time Limit: 2000/10 ...

  3. [SinGuLaRiTy] 2017-07-22 NOIP2017 模拟赛

    [SInGuLaRiTy-1029] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. <全是看看代码就会的水题,偷个懒不单独写题解了~& ...

  4. Java foreach remove问题分析

    原文链接:http://www.cnblogs.com/chrischennx/p/9610853.html 都说ArrayList在用foreach循环的时候,不能add元素,也不能remove元素 ...

  5. CLH同步队列

    原文链接:https://blog.csdn.net/chenssy/article/details/60781148 AQS内部维护着一个FIFO队列,该队列就是CLH同步队列. CLH同步队列是一 ...

  6. P4015 运输问题

    \(\color{#0066ff}{题目描述}\) W 公司有 m 个仓库和 n 个零售商店.第 i 个仓库有 \(a_i\) 个单位的货物:第 j 个零售商店需要 \(b_j\) 个单位的货物. 货 ...

  7. 解决SMON_SCN_TO_TIME_AUX表损坏故障

    同事在给客户做数据库巡检的过程中,发现其中一个数据库的alert日志中报了一个坏块的错误信息,具体如下: Reading datafile '+DATA_DW/xtdw/datafile/sysaux ...

  8. git commit 操作

    查看提交历史 然后在此项目中运行 git log,应该会看到下面的输出:   合并commit 信息 我们需要将 2dfbc7e8 和 c4e858b5 合并成一个 commit,那么我们输入如下命令 ...

  9. 75th LeetCode Weekly Contest Champagne Tower

    We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so ...

  10. datatables通过ajax调用渲染数据,怎么根据数据给td添加class

    html: <table id="table8" cellpadding="0" cellspacing="0" border=&qu ...