返回首页
文学网 > 短句 > 经典短句 > 正文

理解goto语句的替代方式分析

2026/02/23经典短句

文学网整理的理解goto语句的替代方式分析(精选51条),供大家参考,希望能给您提供帮助。

理解goto语句的替代方式分析 篇1

1、return;

2、// operation one

3、复制代码 代码如下:

4、when_failed:

5、}

6、throw Exception;

7、} catch (Exception e) {

8、if (failed) {

9、goto when_failed;

10、用try/catch/finally便可实现同等于goto的功能,来看二个示例:

11、}

12、}

13、有太多的理由不让用goto,但有时,我们又想使用goto的功能,怎么办?

14、if (failed) {

15、// operation one

16、if (failed) {

17、if (failed) {

18、}

19、}

20、try {

21、if (failed) {

22、throw Exception;

23、和:

理解goto语句的替代方式分析 篇2

1、if (failed) {

2、复制代码 代码如下:

3、try {

4、throw Exception;

5、}

6、// operation one

7、}

8、if (failed) {

9、// do something when cases failed

10、// do something when failed

11、复制代码 代码如下:

12、}

13、throw Exception;

14、try {

15、if (failed) {

16、// operation three

17、有太多的理由不让用goto,但有时,我们又想使用goto的功能,怎么办?

18、try {

19、// operation two

20、和:

21、return;

22、return;

23、}

24、复制代码 代码如下:

25、// operation three

26、goto when_failed;

27、goto when_failed;

28、用try/catch/finally便可实现同等于goto的功能,来看二个示例: