使用goto有什么问题? [英] What is wrong with using goto?

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

问题描述


可能的重复项:

代码。



在过去的编程语言中没有while()if()等等,程序员使用goto来构成他们程序的逻辑。



这就是为什么CS神创建函数条件和循环的原因。 结构化节目是当时的一场革命。



goto的适合在几个地方,如跳出嵌套循环


Possible Duplicates:
Why is it bad to use goto?
GOTO still considered harmful?

I was ramdomming through xkcd and saw this one (if also read some negative texts about them some years ago):

What is actually wrong with it? Why are goto's even possible in C++ then?

Why should I not use them?

解决方案

Because they lead to spaghetti code.

In the past programming languages didn't have while() if() etc, and programmers used goto to make up the logic of their programs. It lead to an unmaintainable mess.

That's why the CS gods created functions conditionals and loops. Structured programming was a revolution at the time.

goto's are appropriate in a few places, such as for jumping out of nested loops

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

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