Swift 2.0 学习第2天: 基本操作符
来源:互联网 发布:sql语言入门教程 编辑:程序博客网 时间:2024/05/06 21:55
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
/*
一元操作符(只有一个操作数,与操作符之间不能有空格)
二元操作符(有两个操作数)
三元操作符(目前只有一个 ? :)
*/
/*-1-**********操作符**********/
var char:String
char = String("1") +String("2")+"\(3)"
print(char)
let temp = 5
let sum = -7
let mode = sum%temp
let shang = sum/temp
print(shang)
print(mode)
let myValue = shang*temp+mode
if myValue ==sum {
print("数据正确 =\(myValue)")
}else {
print("数据可能出错了..")
}
//三目运算符,简单找出最小值和最大值
let a = 78, b =98, c =65
let min = a >b ? (b >c ?c : b) : (a >c ?c :a)
let max = a >b ? (a >c ?a : c) : (b >c ?b :c)
print(min)
print(max)
//区间运算符
let arr:Array = ["0","1","2","3"]
for i in 0 ..< arr.count {//半开半闭操作符
print(arr[i])
}
print("------------")
for i in 0...6 {//闭区间操作符
print(i)
}
//逻辑运算符
// ! 逻辑非
// && 逻辑与
// || 逻辑或
//使用括号改变其优先级,可读性,不易出错
let x = 2, y =2, z =3
if x==3 || (y==2 &&z==3) {
print("对了..")
}else {
print("错了..")
}
- Swift 2.0 学习第2天: 基本操作符
- swift学习第一天 基本语法
- [Swift 学习] 第一篇:基本语法
- ios学习swift第一天,基本语法
- 02-Swift 基本操作符
- swift学习2:基本语法
- Swift 语言指南,Swift Language Guide,第2章基本运算符
- 第三章swift 基本的操作符
- 【swift总结】基本的操作运行符
- 第三节swift 算数操作符(+,-,*,/)
- 第八节swift 比较操作符
- QT学习第一天-----基本操作
- swift学习笔记(2)-基本运算符
- Swift学习记录 -- 7.数组的基本操作
- Swift学习记录 -- 8.字典的基本操作
- Swift学习记录 -- 15.tableView的创建与基本操作
- Swift 2.0 学习第3天: 字典和数组
- Swift 2.0 学习第4天:控制流
- jquery array remove duplicate records
- 常用Oracle分析函数详解
- Android 4K高清图片解码显示(1)安卓内存分析
- c++STL 中的copy函数
- ROS进阶学习手记 10 - 搭建自己的TurtleBot(3)- Velocity Calibration
- Swift 2.0 学习第2天: 基本操作符
- 关于语言类型系统
- HTTP Status 500 - Error instantiating servlet class test.Test
- 敏捷开发 - 敏捷工具
- 图像的深度和通道
- JS中页面加载事件window.onload、onload()、document.onclick
- 【软件工程】:非功能需求
- NOIP2015 运输计划
- VS的IISExpress配置通过IP访问程序