课程: Complete Guide to C Programming Foundations

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Avoiding the goto keyword

Avoiding the goto keyword

- [Instructor] The GOTO keyword alters program flow, but it does so in a manner that's difficult to follow. Therefore, using it isn't advised, nor is it even necessary. This exercise file shows the GOTO construction. The keyword at line 11 is followed by a label which indicates where execution jumps. The label is located at line seven at the start of the line. The label name is followed by a colon, not a semicolon. This is the label format in C with a label name using the same naming convention as for a variable. The GOTO jump works only within a function. So both the GOTO statement and its label appear here in the main function. Effectively, this code shows a loop counting down from 10 to one, and there's the output. Better ways are available to generate this same type of output without using a GOTO statement. Further, you can't use a break keyword to disrupt such a loop because a loop isn't truly implemented here, there's nothing to break. Here you see one way to break out of a GOTO…

内容