Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
2.6k views
in Computer by (69.2k points)

Compare the following pairs of statements with respect to their syntax and function: a. break and continue. b. goto and break. 

1 Answer

0 votes
by (70.0k points)
selected by
 
Best answer

a. break and continue

Two keywords that are very important to looping are break and continue.

The break command will exit the most immediately surrounding loop regardless of what the conditions of the loop are. Break is useful if we want to exit a loop under special circumstances. 

#include

void main()

{

int a;

printf("Pick a number from 1 to 4:\n");

scanf("%d", &a); switch (a)

{

case 1:

printf("You chose number 1\n"); 

break; 

 case 2: 

printf("You chose number 2\n");

break;

case 3:

printf("You chose number 3\n");

break;

case 4:

printf("You chose number 4\n");

break;

default: printf("That's not 1,2,3 or 4!\n");

}

getch();

Continue is another keyword that controls the flow of loops. If we are executing a loop and hit a continue statement, the loop will stop its current iteration, update itself (in the case of for loops) and begin to execute again from the top. Essentially, the continue statement is saying "this iteration of the loop is done; let's continue with the loop without executing whatever code comes after me." The syntax of continue statement is simple continue; 

b. goto and break

C support goto statement to branch unconditionally from one point to another in the program.The goto keyword is followed by a label, which is basically some identifier placed elsewhere in the program where the control is to be transferred. During running of a program, the statement like “goto label1;” cause the flow of control to the statement immediately following the label “label1”. We can have a forward jump or a backward jump.

#include<studio.h>

void main()

{

int attempt,

number = 46; looping: /* a label */

printf("Guess a number from 0-100\n");

scanf("%d", &attempt); if(number==attempt)

{

printf("You guessed correctly!\n\n");

}

else

{

printf("Let me ask again...\n\n");

goto looping; /* Jump to the label*/

} getch();

}  

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...