大家好,又见面了,我是你们的朋友全栈君。
3、下面的程序就很好的能反应出switch 中的 break / continue 用法,同时 pro 没定义也不会出错:
/*************************************************************************
> File Name: t.c
> Author: Wenfei6316
> Mail: 2500873570@qq.com
> Created Time: 2018年03月12日 星期一 20时37分51秒
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
int i = 0;
int num = 3;
while (num)
{
printf("++++++++++++++++++++++++++++++++++\n");
switch (i)
{
case 0:
printf("i = %d\n", i++);
i++;
case 1:
printf("i = %d\n", i);
i = i + 2;
continue;
case 2:
printf("i = %d\n", i--);
i--;
break;
case 3:
printf("i = %d\n", i);
continue;
case 4:
printf("i = %d\n", i);
i++;
break;
default:
printf("i = %d\n", i);
i = 2;
break;
}
printf("----------------------------------\n");
num--;
printf("num = %d\n", num);
}
pro:
printf("hello world!\n");
return 0;
}
运行结果如下:
++++++++++++++++++++++++++++++++++
i = 0
i = 2
++++++++++++++++++++++++++++++++++
i = 4
----------------------------------
num = 2
++++++++++++++++++++++++++++++++++
i = 5
----------------------------------
num = 1
++++++++++++++++++++++++++++++++++
i = 2
----------------------------------
num = 0
hello world!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/137431.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...