先来看看goto
#include<stdio.h>void main(){int i,j, count =0;for (i = 1; i <= 10; i++){for (j = 1; j <= 3; j++){if (i == 6)goto stop;/*跳出外循环*/count++;}}stop:printf(\"i=%d\", i);printf(\"循环次数%d\", count);}
输出i=5 循环次数15
再来看看break
#include<stdio.h>void main(){int i,j, count =0;for (i = 1; i <= 10; i++){for (j = 1; j <= 3; j++){if (i == 6)break;/*跳出内循环*/count++;}}printf(\"i=%d\", i);printf(\"循环次数%d\", count);}
输出i=11,循环次数27
最后来看看continue
#include<stdio.h>void main(){int i,j, count =0;for (i = 1; i <= 10; i++){for (j = 1; j <= 3; j++){if (j == 2)continue;/*挖去j=2所有情况*/count++;}}printf(\"i=%d\", i);printf(\"循环次数%d\", count);}
输出i=11 循环次数20