Goto
大家一定听过goto语句。这种用法会打破编码的规则,原则上最好不要使用。但是事实上在c的项目中还是比较常见的。当然C++也是保留这中用法的,为了方便大家在VisualStudio中运行,就直接写Cpp了。
用例
#include<iostream>
int main(){
int choose;
TryAgain:
std::cout<<"input your choose:";
scanf_s("%d", &choose);
if(choose)
printf("%d\n",choose);
else
{
printf("please dont input number 0\n");
goto TryAgain;
}
printf("process exit!");
return 0;
}
注意
但是请最好避免这种用法,因为这其实有违背于编码规则。因为大量的使用goto会使得程序逻辑性,可读性和安全性大大降低。但是合理的使用goto语句也会使程序更加简洁清晰。