Control Statements

Control statements are used to transfer the flow of control of the program . These are generally used inside the executions of condition .
The various statements used for executing loops in C are :


StatementsWhat They Do..Programming
BreakExits a loop , or condition . Structured
ContinueOne iteration of loop is excluded .Structured
GotoTransfers the control to any other line .Unstructured



Break Statement

1. break statement is used for exiting a certain block of statements ,i.e, transfering the flow of control to the outside of loop.
2. It can be used in for loop , while loop , switch statements or wherever one needs to transfer flow of control.


Syntax for 'Break Control'

break ; 




C Example 1


#include<stdio.h>

int main() {

	int i=1;

	while(i<10) {

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

		if(i==5) {

			break;

		}

		i=i+1;

	}

	printf("loop broken");

	return 0;

}




Output


1

2

3

4

5

loop broken




C Example 2


#include<stdio.h>

int main() {

	int i;

	for (i=1;i<5;i++) {

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

		if(i==3) {

			break;

		}

	}

	printf("loop broken");

	return 0;

}


Quantitative Aptitude
Reasoning
Programming
Interview