< Prev
Next >



Break Statement





In C language, when a break statement is encountered within a loop of a program, it stops executing the remaining statements in the loop and takes the control out of it to execute the first statement right after the loop.




Note :


Break statement must be inside a loop, otherwise a compile error is issued by Java Compiler at the time of compilation of the program..







Break statement example


/* C - Break statement example */

#include<stdio.h>

int main()      /* main method starts */
{

for(int i=0;i<10;i++)
{
	if(i==5)
		break;	/* when i is equal to 5, break statement takes the control out of loop */

	printf("i = %d \n",i);
}

printf("Out of the loop");

return 0;
} /* main method ends and so does the program */


Output


i = 0
i = 1
i = 2
i = 3
i = 4
Out of the loop

As you can see in the program and its output, when i is equal to 5, break statement breaks the execution of the loop and it takes the control out of loop to execute the first statement outside the loop.



Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter




< Prev
Next >
< While Loop
Switch Statement>

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page

Notifications



COMING SOON
-
PYTHON