The BREAK statement is basically used to get out of the loop. When the break statement is encountered the control is automatically transferred to the statement executing just after the curly braces of the loop i.e. it allows us to get out of the existing loop at any instant of time.



/*Demonstration of break statement*/

main( )
{
int n, count ;
printf ( "Enter a number " ) ;
scanf ( "%d", &n ) ;
count = 2 ;
while ( count <= n - 1 )
{
if ( n % count == 0 )
{
printf ( "Not a prime number" ) ;
break ;
}
count++ ;
}
if ( count == n )
printf ( "Prime number" ) ;
}



0 comments to "BREAK STATEMENT IN C"

Post a Comment

Powered by Blogger.