示例:
/*** @brief how about goto-switch? show you here.* @author wen`xuanpei* @email 15873152445@163.com(query for any question here)*/
#define _CRT_SECURE_NO_WARNINGS//support c-library in Microsoft-Visual-Studio
#include <stdio.h>static void goto_switch_stmt(int n) {int trace = 0;
__switch_begin:if(1 == n || 2 == n)goto __case1_2;else if(3 == n)goto __case3;elsegoto __switch_default;
__case1_2:{++trace, printf("Y1:%d\n", n);goto __switch_end;
}
__case3:{++trace, printf("Y2:%d\n", n);goto __switch_end;
}
__switch_default:++trace, printf("N:%d\n", n);
__switch_end:printf("%d\n", trace);
}int main(){goto_switch_stmt(1);goto_switch_stmt(2);goto_switch_stmt(3);goto_switch_stmt(4);getchar();return 0;
}
1)编译运行
2)要点分析
1)判断条件表达式,非0即1
2)条件表达式可以是任何整数、浮点数、任意类型
3)直接选择一个满足条件的分支,进入里面并执行
4)多个分支的标签可以合并
尾声:
其它不明白的地方不用过于纠结,那只是在浪费时间。学得多了,回过头来看自然融会贯通。