本文介绍了如何在C ++中避免GOTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读到GOTO不好,但是如何避免呢?我不知道如何在没有GOTO的情况下进行编程.在BASIC中,我将GOTO用于所有内容.在C和C ++中应该使用什么代替?

I have read that GOTO is bad, but how do I avoid it? I don't know how to program without GOTO. In BASIC I used GOTO for everything. What should I use instead in C and C++?

我在BASIC中像这样使用GOTO:

I used GOTO in BASIC like this:

MainLoop:
INPUT string$
IF string$ = "game" THEN
GOTO game
ENDIF

推荐答案

通常,像forwhiledo while这样的循环和函数或多或少地消除了使用GOTO的需要.了解有关使用这些功能的信息,并在几个示例之后,您将不再考虑goto. :)

Usually loops like for, while and do while and functions have more or less disposed the need of using GOTO. Learn about using those and after a few examples you won't think about goto anymore. :)

这篇关于如何在C ++中避免GOTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:55