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 - Terminating loops with break

Node:Terminating loops with break, Next:, Previous:Terminating and speeding loops, Up:Terminating and speeding loops



Terminating loops with break

The usual statement to terminate a loop is the same statement that is used to jump out of switch statements:

break;

If this statement is encountered within a loop, the loop will end immediately. For instance, here is an inefficient way of assigning 12 to my_int:

for (my_int = 1; my_int <= 100; my_int++)
{
  if (my_int == 12)
  {
    break;
  }
}

printf("my_int = %d\n\n", my_int);

 
 
  Published under free license. Design by Interspire