Fundamentals of Computer Programming - Old Questions
Question Answer Details
5. Differentiate between break and continue statement. Write a program to display following output. [2+4]
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1
Answer
AI Generated Answer
AI is thinking...
Official Answer
Difference between break and continue statement
Break | Continue |
Break is used to break loop or iteration. | Continue continues the loop or iteration. |
Used with switch case loop. | Not used with switch case. |
Keyword used is "break". | Keyword used is "continue". |
Breaks loop and allows coming out from it. | Allows iterating in the loop. |
Control is transferred outside the loop. | Control remains in the same loop. |
E.g.
Output: 1, 2 | E.g.
Output: 1, 2, 4, 5 |
Program to display given output
#include<stdio.h>
#include<conio.h>
#define n 5
int main()
{
int i, j;
for(i=1;i<=n;i++)
{
for(j=1;j<=1;j++)
{
printf("\\t1");
}
printf("\\n");
}
getch();
return 0;
}