Home   Programming   Hardware   Networking
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.  

C Categories

Break Statement

« Previous Point - Switch Case Statement Next Point - Continue Statement »


Break statement terminates the current execution of loop(block) like while, do-while, for loop etc. and passes the execution control to the next statement after the loop.

Source code

  • //Using break statement
  • #include <stdio.h>
  • void main()
  • {
  • 	int a;
  • 	while(1)
  • 	{
  • 	printf("\n\nEnter 1 to break the loop : ");
  • 	scanf("%d",&a);
  • 	if(a==1)
  • 		break;
  • 	else
  • 		printf("Didn't break the while loop");
  • 	}
  • 	printf("\nWhile loop terminated");
  • }

Program working steps

  • Comment, declaration of preprocessor directive and void main function at the start.
  • Variable int a is declared, while(1) statement is a repetative loop it will terminate only when break statement is executed.
  • Programs asks the user to enter 1 to break the loop, if user enters 1 it will break the while loop printing 'While loop terminated'. Else, if user enters any other integer value the loop will be repeated, printing 'Didn't break the while loop'.

« Previous Point - Switch Case Statement Next Point - Continue Statement »

Tip Box


Break statement takes the program control out-off inner-most loop




Terms of Use | Privacy Policy | Contact Us
CodesandTutorials © 2014 All Rights Reserved