212 字
1 分钟
goto语句
跳转语句
C语言的跳转语句主要包括continue,break,retuen,还有就是goto啦
goto语句
goto语句是在所有跳转语句中最自由的一种,但在大型工程和多人协作工程中并不推荐,原因就在于它
太过于自由,会导致代码的可读性变得较差但这也无法撼动
goto语句的地位合理的使用goto会大大简化代码,并且使程序逻辑更加清晰
什么是goto语句
goto,又称无条件跳转语句,使用goto语句可以直接跳转到label标注处,其语法为goto lable;
示例
#include<iostream>using namespace std;int main(){ for (int i = 1; i <= 10; ++ i){ printf("%d ", i); if (i == 6){ goto ERA; } } cout << "Before ending" << endl; ERA: cout << "end" << endl;}输出
1 2 3 4 5 6 end