一、基本运算
1.位运算:针对2进制
按位与:&
按位或:|
按位异或:^
按位取反:~
左移动:<<
右移动:>>
2.算数运算符
+(加号) 加法运算
–(减号) 减法运算
*(星号) 乘法运算
/(正斜线) 除法运算
%(百分号) 求余运算
–(减号) 减法运算
*(星号) 乘法运算
/(正斜线) 除法运算
%(百分号) 求余运算
3.关系运算符
< 小于
<= 小于等于
> 大于
>= 大于等于
== 等于
!= 不等于
4.逻辑运算符
&& 与
|| 或
! 非
5.赋值运算符
=:a=10
+=:a+=b等价于a=a+b
等价相关还有:-=\*=\
自增++
自减--
一元运算符:对一个变量OR常量进行操作
二元运算符:对二个变量OR常量进行操作
OC中存在唯一三元运算表达式:
a=100;
b=200;
int better=a>b?a:b;
二、程序控制流程
1.选择
选择:if
if (condition) {
statements
}
选择:if-else
if (condition) {
statements-if-ture
} else {
statements-if-false
}
选择:if-else if-else
if (condition) {
statements }else if (experssion){
statements }else if (experssion){
statements }else {
statements
}
选择:switch
switch (expression) {
case constant:
statements
break;
…...
default:
break;
}
2.循环
循环:for
for (initialization; condition; increment) { statements }
循环:while
while (condition) { statements }
循环:do-while
do { statements } while (condition);
3.顺序
顺序是永恒的主线,循环、选择仅仅是“插曲”。