Home C Programming Language / Programs / C program break statement in for loop
🚀 Programming Example

C program break statement in for loop

👁 1,001 Views
💻 Practical Program
📘 Step Learning

The break statement has two uses. You can use it to terminate a case in the switch statement. You can also use it to force immediate termination of a loop, bypassing the normal loop conditional test. When the break statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop. For example,

💻 Program Code

#include <stdio.h>
void main ()
{ 
int a =  0 ; 
while( a < 100 )
{
	printf("value of a: %d\n", a);
	a++;
	if( a == 50 )
	{ 
	 break;
	}
 }
 
}
                        

🖥 Program Output

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
Press any key to continue . . .
                            

📘 Explanation

This will print 10 to 16 after that break will terminate the loop. When the break statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.