The break keyword escapes from a block of statements in a loop, halting the loop—or structure—where it appears, skipping over any remaining statements in the block, and breaking out into the next level of code. Use the break keyword to halt a loop, escaping as an exit condition or when circumstances otherwise warrant ending the loop.
- [Instructor] A loop repeats it statements … until the terminating condition is met … or until a break statement is encountered. … In this code, input from the user is requested. … The value input is used … to determine how many times the loop spins. … The if test at line 12 compares the value input with nine, … once it reaches this value, no matter what was input, … the loop is broken. … Execution continues after the loop's block of statements. … Build and run the code. … And I'm going to type a huge value, 300. … But the loop repeats only 10 times. … The if statement at line 12 test to see … whether the value of variable a is equal to nine. … If so, its sole statement break is executed. … And it counts 10 times … because zero through nine is equal to 10. … When used in a nested loop, … break halts only the loop it's in. … Here you see nested loops, … an outer loop and an inner loop. … At line 13, a test is made … to determine whether the value of variable column … is equal to the letter E. …
- 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.