knowledgediarybd.com

Your Virtual Knowledge Campus

Continue and Break Statement In C

break and continue statementContinue and Break Statement are used  in C for controlling  various kind of loop such as for loop, while loop & do..while loop etc.

1.The continue Keyword:

The continue keyword can be used in any of the loop control structures. It causes the loop to immediately jump to the next iteration of the loop.

  1. In a for loop, the continue keyword causes flow of control to immediately jump to the update statement.
  2. In a while loop or do/while loop, flow of control immediately jumps to the Boolean expression.

Syntax of Continue Statement:

continue;

More details see the following figure:

continue statement

Example of continue statement:

#include
int main()
{int count=0,total=0,score;
while(count<4)
{
printf("\nEnter your Score:");
scanf("%d",&score);
if((score<0)||(score>100))
continue;
total=total+score;
printf("\nTotal score is:%d",total);
count++;
}
return 0;
}

The output of the above code looks like below:

Enter your Score:25Total score is:25

Enter your Score:10Total score is:35

Enter your Score:25

Total score is:60

Enter your Score:10

Total score is:70

2. The break Keyword or Statement:

The break keyword is used to stop the entire loop. The break keyword must be used inside any loop or a switch statement.

The break keyword will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax:

break;

More details see the following figure:

break  statement

Example of break Statement:

#include
int main()
{
int i,array[5]={10,20,30,40,50};
for (i=0;i<5;i++)
{
if (array[i]==40)
break;
else
printf("\narray:%d",array[i]);
}
return 0;
}

This would produce the following result:

array:10

array:20

array:30

Note:More interested things are waiting to publish..Stay connected to us..

——————-:Thank you:—————–

Related Post or you may fell interest:

  1. Introduction & Fundamental of C
  2. Turbo C Compiler Download & Installing
  3. Variable In C
  4. Data Types In C
  5. Token in c
  6. C Operators,Operands and expression
  7. If, Else If..Else & Switch Statement
  8. For loop while loop and Do while loop in C
knowledgediarybd.com © 2017
shares