标题:goto 语句怎么用啊
只看楼主
tiantian0623
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-23
 问题点数:0 回复次数:1 
goto 语句怎么用啊
举个具体的例子
搜索更多相关主题的帖子: goto 语句 
2008-04-23 22:49
freedomz
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-4-7
得分:0 
程序代码:
#include <iostream.h>

int main()
{
    int counter=0;
    Loop:   //所要 goto 的地方
    cout<<"This loop runs for 10 times"<<endl;
    counter++;
    if(counter!=10)
        goto Loop;//goto 指定的地方
    return 0;
}




其实goto虽然方便,可是却是一个很乱的编程方法,好的程序里面是不应该有goto的。尽量用loop,,recursion,function call来解决问题。

[[it] 本帖最后由 freedomz 于 2008-4-23 23:37 编辑 [/it]]
2008-04-23 23:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210751-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.268363 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved