Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Speeding loops with continue

Node:Speeding loops with continue, Previous:Terminating loops with return, Up:Terminating and speeding loops



Speeding loops with continue

Instead of terminating a loop, you might want to speed it to its next pass, perhaps to avoid executing irrelevant statements. To do so, you should use the continue statement. When a continue statement is encountered, the program will skip the rest of the loop's code block and jump straight to the start of the next pass through the loop.

Here is an example that uses the continue statement to avoid division by zero (which causes a run-time error):

for (my_int = -10; my_int <= 10; my_int++)
{
  if (my_int == 0)
  {
    continue;
  }

  printf ("%d", 20/i);
}

 
 
  Published under free license. Design by Interspire