for - break
for (int i = 0; i < 10; i++) {
if (i == 5) {
break;
}
NSLog(@"%d",i);
}
2021-02-14 13:43:01.381145+0800 multithreading[36561:13680387] 0
2021-02-14 13:43:01.381433+0800 multithreading[36561:13680387] 1
2021-02-14 13:43:01.381550+0800 multithreading[36561:13680387] 2
2021-02-14 13:43:01.381657+0800 multithreading[36561:13680387] 3
2021-02-14 13:43:01.381752+0800 multithreading[36561:13680387] 4
for -continue
for (int i = 0; i < 10; i++) {
if (i == 5) {
continue;;
}
NSLog(@"%d",i);
}
2021-02-14 13:45:11.739404+0800 multithreading[36625:13683579] 0
2021-02-14 13:45:11.739533+0800 multithreading[36625:13683579] 1
2021-02-14 13:45:11.740154+0800 multithreading[36625:13683579] 2
2021-02-14 13:45:11.740287+0800 multithreading[36625:13683579] 3
2021-02-14 13:45:11.740415+0800 multithreading[36625:13683579] 4
2021-02-14 13:45:11.741378+0800 multithreading[36625:13683579] 6
2021-02-14 13:45:11.741472+0800 multithreading[36625:13683579] 7
2021-02-14 13:45:11.741568+0800 multithreading[36625:13683579] 8
2021-02-14 13:45:11.741649+0800 multithreading[36625:13683579] 9
while -break
for (int i = 0; i < 10; i++) {
if (i == 5) {
continue;;
}
NSLog(@"%d",i);
}
2021-02-14 13:46:13.206855+0800 multithreading[36644:13684516] 0
2021-02-14 13:46:13.207093+0800 multithreading[36644:13684516] 1
2021-02-14 13:46:13.207323+0800 multithreading[36644:13684516] 2
2021-02-14 13:46:13.207447+0800 multithreading[36644:13684516] 3
2021-02-14 13:46:13.207627+0800 multithreading[36644:13684516] 4
while - continue
int i = 0;
while (i < 10) {
if (i == 5) {
continue;
}
NSLog(@"%d",i);
i++;
}
2021-02-14 13:46:47.111638+0800 multithreading[36664:13685416] 0
2021-02-14 13:46:47.111771+0800 multithreading[36664:13685416] 1
2021-02-14 13:46:47.111860+0800 multithreading[36664:13685416] 2
2021-02-14 13:46:47.111964+0800 multithreading[36664:13685416] 3
2021-02-14 13:46:47.112049+0800 multithreading[36664:13685416] 4
注意:
while使用continue,后面的i++
不会执行,所以下一次循环i
人就等于5,循环永远出不去。
网友评论