联系我(内含技术交流群及个人微信):https://mp.weixin.qq.com/s/d6L3zmwGIor7QmuGoJHeNQ
记得上学的时候老师说goto使用的基本原则是:不用goto
确实goto会带来一些问题:导致程序不稳定,代码不易读
goto实现判断函数的基本使用
#include
void main() {
int age;
gotolabel: //注意是:
printf("You are not eligible to vote!\n");
printf("Enter you age:\n");
scanf("%d", &age);
if (age < 18) {
goto gotolabel; //跳转到gotolabel
}else {
printf("You are eligible to vote!\n");
}
}
实验:副作用分析(很明显例子中goto的使用导致出现了不可预期的错误)