Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

Break Statement-:


1- break is a keyword.
2-The break statement is used within a loop or switch statement on execution,it transfer the control outside the loop or switch statement within which it is enclosed.
3-The break statement should always be dependent upon a condition.
ads

Syntax of break statement in for loop-:
for( _ ; _ ;_ )
    {     _
           _
       if(condition)
            break;
       else
              _
              _
      }
Example of break statement in for loop -:
#include<stdio.h>
#include<conio.h>
main()
{ int i=1;
   for(i=1;i<=5;i++)
{ if(i==3)
   break;
   else
   printf(" %d \n ",i);
 }
   getch();
  }
    Output-:  1
                     2
Syntax of break statement in while loop-:
while(condition)
    {     _
           _
       if(condition)
            break;
       else
              _
              _
      }
Example of break statement in while loop -:
#include<stdio.h>
#include<conio.h>
main()
{ int i=1;
   while(i<=5)
{ if(i==3)
   break;
   else
   printf(" %d \n ",i);
    i++;
 }
  getch();
  }
    Output-:  1
                     2
Syntax of break statement in do-while loop-:
main()
{initialize;
  do
    {     _
           _
       if(condition)
            break;
       else
              _
              _
      }while(condition);
}
Example of break statement in do-while loop -:
#include<stdio.h>
#include<conio.h>
main()
{ int i=1;
   do
{ if(i==3)
   break;
    else
    printf(" %d \n ",i);
    i++;
 } while(i<=5);
    getch();
  }
    Output-:  1
                     2 
ads
Learn how break statement works in Switch statement- CLICK HERE
Watch The Video Below


Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey