From the course: C Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Avoiding the goto keyword - C Tutorial
From the course: C Essential Training
Avoiding the goto keyword
- 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Making a decision3m 37s
-
(Locked)
Exploring the possibilities2m 34s
-
(Locked)
Using the ternary operator3m 1s
-
Working with the switch-case structure4m 9s
-
(Locked)
Challenge: Select an item29s
-
(Locked)
Solution: Select an item57s
-
(Locked)
Creating a for loop3m 58s
-
(Locked)
Setting up a while loop3m 6s
-
(Locked)
Challenge: Repeat some text48s
-
(Locked)
Solution: Repeat some text1m 40s
-
(Locked)
Nesting loops1m 55s
-
(Locked)
Breaking out of a loop3m 28s
-
(Locked)
Avoiding the goto keyword1m 56s
-
(Locked)
Challenge: Work the grid2m 21s
-
(Locked)
Solution: Work the grid2m 8s
-
-
-