Break Statement in C

Advertisements

Prev Tutorial Next Tutorial

Break Statement in C

Break statement are used for terminates any type of loop e.g, while loop, do while loop or for loop. The break statement terminates the loop body immediately and passes control to the next statement after the loop. In case of inner loops, it terminates the control of inner loop only.

Use break statement

Break statement are mainly used with loop and switch statement. often use the break statement with the if statement.

  • with loop statement
  • with switch case
  • with if statement

Syntax

jump-statements (loop or switch case);
break;

Example of break

#include<stdio.h>
#include<conio.h>

void main()
{
char key;
 
printf("Press any key or E to exit:\n");
while(1)
{
scanf("%c", &key);
if (key == 'E' ||  key == 'e')
break;
}
printf("Good bye !\n");
}

Explanation:In the above code when user enter any character, if the user enters E or e, the break statement terminates the while loop and control is passed to the statement after the while loop that displays the Good bye !message.

Output

Press any key or E to exit
Good bye !

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements