Course contentsShow
← C
Lesson 831 of 1,21911. The Preprocessor and BuildFree lesson

Continuing execution with `continue`

Continuing execution with continue

What you'll learn: How to resume your program's normal operation after it has been paused by a breakpoint.

The "Play" Button

When you are debugging a program in GDB, you often use breakpoints to freeze time. Once the program hits a breakpoint, it sits there, waiting for your command. While you can step through your code line-by-line, sometimes you just want the program to keep running until it finishes or hits the next "speed bump" you’ve set.

Think of it like watching a movie. You’ve pressed Pause to look at a specific frame. Once you are done inspecting that scene, you don't necessarily want to watch the rest of the movie frame-by-frame (which is what "stepping" does). You want to hit Play and let the movie run normally until the next scene you care about. In GDB, the continue command is your Play button.

How to use it

To resume your program, simply type continue (or just the letter c) into the GDB prompt and press Enter.

#include <stdio.h>

int main() {
    printf("Starting the engine...\n");
    // Assume we set a breakpoint here
    printf("Mid-way through the process.\n");
    printf("Finish line reached!\n");
    return 0;
}

If your program is paused at the "Mid-way" line, typing c tells GDB: "Stop hovering over me and just run until you hit another breakpoint or the program exits."

Why use Continue?

There are two main reasons to use continue instead of stepping:

  1. Skipping the Boring Parts: If you have a loop that runs 1,000 times, you don't want to press "next" 1,000 times. You set a breakpoint after the loop and hit continue to jump straight there.
  2. Moving Between Breakpoints: If you have a bug at the start of your code and another at the end, you can fix your focus on the first, then continue to jump immediately to the second point of interest without manually navigating every line in between.

If your program is stuck in an infinite loop, continue will make it run forever, just like a normal execution. If that happens, you can usually press Ctrl+C to force it to pause again.

Key takeaway

Use continue (or c) to resume normal execution until the next breakpoint or the end of the program.