-
循环结构:for循环,break、continue,while循环,do while循环
-
循环结构:在一定条件下,循环执行某段程序(语句),被执行的程序(语句)称为“循环体”
-
随机数:arc4random()%(b-a+1)+a
-
for循环:
for(循环变量初始化;循环条件;循环变量增量){
循环体;
}
-
break:循环语句中,跳出本层循环
-
前提:(for循环中包含switch语句和if语句,且if语句在switch下面)
-
将switch中的break更改为continue,使得程序从switch中跳出来,且不执行switch下面的语句,但是不影响整个for循环的执行,直到满足循环结束条件。
-
switch中的break是跳出switch本次循环,但是不影响switch下面的语句。当switch下面语句中的if中出现break时,则整个for循环下的语句结束。
- while循环:先判断循环条件是否为真,如果为加,跳出循环;如果为真,则执行循环体语句,直到循环条件为假时,结束循环。注意:while语句包括循环条件和循环语句两部分,循环变量初始化写在while循环前面,而循环变量增量写在循环体内,作为语句的一部分。
- do…while:先执行循环体,再判断循环条件,直到循环条件不满足时,结束循环。注意:使用该语句时,语句至少可以被执行一次。