为什么不使用GOTO ...... [英] why are GOTO's not used ...

查看:81
本文介绍了为什么不使用GOTO ......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么GOTO没有被使用他们只是一个简单的JMP指令什么是坏的

关于他们

why are GOTO''s not used they just a simple JMP instructions what''s bad
about them

推荐答案



" raashid bhatt" < ra ********** @ gmail.com在消息新闻中写道:

"raashid bhatt" <ra**********@gmail.comwrote in message news:

为什么没有使用GOTO'他们只是一个简单的JMP说明什么是坏的

关于他们
why are GOTO''s not used they just a simple JMP instructions what''s bad
about them



的确如此。 C有一个功能完善的goto语句,它将编译为

基本的汇编程序跳转。


-

免费游戏和编程好东西。
http://www.personal.leeds。 ac.uk/~bgy1mm

Indeed. C has a perfectly functional goto statement, which will compile to a
basic assembler jump.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


raashid bhatt说:
raashid bhatt said:

为什么GOTO没有被使用他们只是一个简单的JMP指令什么是坏的

关于他们
why are GOTO''s not used they just a simple JMP instructions what''s bad
about them



goto尝试


拒绝使用它们。然后等六个月。然后去做一些

转到中等规模


然后再等半年。然后去做一些中等规模的更改

转到代码


代码的中等规模变化(不是整容,但不是大手术

转到


现在尝试不用它们。具体来说,写一个大程序,你在其中

转到拒绝


代码(不是化妆品,但也不是大手术)。考虑有多困难

转到这个


)。考虑相对于其他程序来说这是多么容易。

转到结束


这是。

转到现在


试试吧。具体来说,写一个大型程序,你可以自由使用它们。

goto然后


结束


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

goto Try

refuse to use them at all. Then wait six months. Then go and make some
goto medium-scale

Then wait six months. Then go and make some medium-scale changes to the
goto code

medium-scale changes to the code (not cosmetic, but not drastic surgery
goto either

Now try without them. Specifically, write a large program in which you
goto refuse

code (not cosmetic, but not drastic surgery either). Consider how difficult
goto this

either). Consider how easy this is, relative to the other program.
goto end

this is.
goto Now

Try them. Specifically, write a large program in which you use them freely.
goto Then

end

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


Malcolm McLean写道:
Malcolm McLean wrote:

>

raashid bhatt < ra ********** @ gmail.com在消息新闻中写道:
>
"raashid bhatt" <ra**********@gmail.comwrote in message news:

>为什么GOTO没有被使用他们只是一个简单的JMP说明对他们有什么不好
>why are GOTO''s not used they just a simple JMP instructions what''s
bad about them



的确如此。 C有一个功能完善的goto语句,它将
编译成一个基本的汇编程序跳转。

Indeed. C has a perfectly functional goto statement, which will
compile to a basic assembler jump.



我注意到你没有真正回答OP的问题。


到OP:


说goto是未使用是不正确的。它的使用经常被劝阻,但它仍然在某些情况下被使用。与

获得不同,goto *可以*明智地使用,但根据我的经验,你需要

在编程之前进行相当多的练习才能获得这种能力。

简而言之,goto很容易被初学者滥用(虽然这并不是说*所有*初学者滥用goto或者经验丰富的程序员从不

这样做)。


过度使用往往会打破更高级别代码的结构

和它的控制流程使它难以阅读和难以扩展。它还会抛弃程序员编写特定

结构的意图,高级语句可以保留和传达。


只需比较这两个做同样事情的代码片段:


1.


for(i = 0; i< 10 ; i ++){

for(j = 0; j< 10; j ++){

putc(''*'',stdout);

}

putc(''\ n'',stdout);

}


2.


i = 0;

outer_loop:

if(i == 10){

goto end_loop;

}

else {

i ++;

}

j = 0;

inner_loop:

putc(''*'',stdout);

if(j == 10){

putc(''\ n'',stdout);

goto outer_loop;

}

else {

j ++;

goto inner_loop;

}

end_loop:

/ * proceed * /


您不妨编程在汇编程序中。

I note that you have failed to actually answer the OP''s question.

To the OP:

It''s not true to say that the goto is "not used". It''s use is often
discouraged, but it''s nevertheless used in some situations. Unlike
gets, goto *can* be used wisely, though in my experience, you need
quite some practise in programming before you can acquire this ability.
In short, goto is prone to abuse by beginners (though that''s not to say
that *all* beginners abuse goto or that experienced programmers never
do so).

It''s overuse tends to break up the "higher level" structure of the code
and it''s flow of control making it hard to read and hard to extend. It
also throws away the intent the programmer had in coding a particular
construct which high-level statements can preserve and convey.

Just compare these two code fragments that do the same thing:

1.

for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
putc(''*'', stdout);
}
putc(''\n'', stdout);
}

2.

i = 0;
outer_loop:
if (i == 10) {
goto end_loop;
}
else {
i++;
}
j = 0;
inner_loop:
putc(''*'', stdout);
if (j == 10) {
putc(''\n'', stdout);
goto outer_loop;
}
else {
j++;
goto inner_loop;
}
end_loop:
/* proceed */

You might as well program in assembler.


这篇关于为什么不使用GOTO ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆