The goto keyword alters program flow by branching execution to a label elsewhere in the function. The problem with goto and its labels is that following the code flow can be difficult and fixing such code is a pain, which is why it shouldn't be used.
- The goto keyword … alters program flow … but does so in a manner … that's difficult to follow, … therefore its use isn't recommended, … or 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. … The name is followed by a colon, … not a semicolon, … this is the label format in C. … The label naming convention is the same … as for a variable name. … The goto jump works only within a function, … so both goto and its label … must exist here within the main function. … Effectively, this code is a loop, … it goes down from 10 to one. … Build and run. … There you go. … Better ways are available to generate … this same output without using goto, … further, … you can't use the break keyword … to disrupt this loop, … because the loop really isn't implemented here, … there's nothing to break. … Here you see … one way to break out of a goto construction, …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.