Jumping Statements

Jumping Statements

Published by: Nuru

Published date: 20 Jun 2021

Jumping Statements Photo

Jumping Statements

Jumping statements are particularly used to jump execution of program statements from one place to another place inside a program. These statements may execute the same program statement repeatedly or skip some program statements. The following are the jumping statements defined in the C programming language.

  •  break
  • continue
  • goto

break Statement

As its name implies, it is used to break the normal flow of program statement execution in loop and switch case statement. It allows us to exit from the innermost enclosing loop or switch statements as soon as a certain condition is satisfied.

When ‘break’ is encountered in the program (loop body/switch statement), the remaining part of the loop/switch statement is skipped and control will be passed to the next statement after loop; terminating the loop/switch statement. For example, while searching a number in a set of 100 numbers; when the required number is found it is obvious to get terminated from the loop. In such a case break statement is used to do so.

Example
int main(){
int i;
for(i=1;i<=5;i++)
{
if (i==4){
break;
}
printf(“%d\t”,i);
}
return 0;
}

When the value of 'i' becomes 4 then a break is encountered and control is passed to outside the loop structure.
The output of this program is 1 2 3

continue Statement

As its name implies, it is used to continue the normal flow of program statement execution in a loop; skipping a particular iteration in the loop as soon as a certain condition is satisfied. When ‘continue’ is encountered in the program (loop body) then that particular iteration is skipped and the loop will be continued with the next iteration.

Example
void main()
{
int i;
for(i=1;i<=5;i++)
{
if (i==4)
continue;
printf(“%d\t”,i);
}

When the value of 'i' becomes 4, ‘continue’ is encountered then that iteration for which 'i' equals 4 is skipped and it continues with i equals 5.
Hence, the output of this program is 1 2 3 5