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

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

问题描述

<块引用>

可能的重复:
编程在当时是一场革命.

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 loops, if statements, 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 methods, 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天全站免登陆