Home / Programs / break statement in do while loop
🚀 Programming Example

break statement in do while loop

👁 981 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.

💻 Program Code

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

🖥 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
Press any key to continue . . .
                            

📘 Explanation

This will print 10 to 15, after that the break will take place for that it terminates. 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.