swift 基础笔记七for循环

//: Playground - noun: a place where people can play

import UIKit

// for 循环

//你可以使用for-in循环来遍历一个集合里面的所有元素,例如由数字表示的区间、数组中的元素、字符串中的字符。


for index in 1...5{
    println(index);
}

//如果你不需要知道区间内每一项的值,你可以使用下划线(_)替代变量名来忽略对值的访问
var count = 3;
var one = 1;
var two = 2;
for _ in 1...count{
    one *= two
}

// 遍历数组

var arr1 = ["E","n","d","a"];
for name in arr1{
    println(name);
}

// key + value
var arr2 = [1:"E",2:"n",3:"d",4:"a"];
for (key,value) in arr2{
    println("\(key)==>\(value)")
}


// 遍历字符串

var names = "MyNameisEnda";

for name in names{
    println("\(name)");
}

// for 条件递增
for var index = 0;index<3;++index{
    println(index);
}

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...