Continue Keyword


In C programming, the 'continue' keyword is used within loop structures to skip the remaining statements within the loop and move on to the next iteration.

It provides a way to control the flow of execution within loops based on certain conditions.

Here's an example of using the 'continue' keyword within a loop:


for (int i = 1; i <= 10; i++) {
  if (i % 2 == 0) {
    continue; // Skip the remaining statements and move to the next iteration
  }
  printf("%d ", i);
}

    

In this example, the 'continue' statement is used to skip the remaining statements within the loop if the value of 'i' is even.

When 'i' is divisible by 2, the 'continue' statement is encountered, and the program moves directly to the next iteration, omitting the 'printf' statement. As a result, only the odd numbers from 1 to 10 are printed.

The 'continue' keyword is commonly used in loop structures, such as 'for' and 'while', to control the flow of execution based on specific conditions.

It allows you to bypass certain iterations and focus on the ones that meet your criteria.

Loading...

Search