Un-conditional branch


The sequential statement are executed one after the other . However, we can give instruction the control from one statement to some other statement during execution of the program these statements that transfer the control from the one statement to other statement without any condition are called un-conditional branching statements.

Un-conditional branch statement


goto statement

The sequential statement are executed one after the other but if the programmer wants to transfer the control from one point to some other point in the program the goto statement can be used duing this statement control can be transferred from one statement to the specified statement without any condition.
Syntax:-
     goto label:
Here;- goto is a keyword.
            label is a identifier ending with the colon “ : “  .

W.A.P to print the sum of 1 to 10.

#include<stdio.h>
#include<conio.h>
void main()
 {
  int sum=0,i=0;
  top:
  if(i>10)
 {
  goto end;
 }
  sum=sum+i;
  i++;>
  goto top;
  end: printf(“%d”,sum);
  getch();
 }

Output

     55

break

The break is a keyword that are used as a jump statement which can be used in switch and looping statement
The break statement in C programming has following two stages:-
Syntax:-
   for(……)
  {
    ………
    if(condition)
    break
    ……..
  }
Note:- the break statement causes the inner loop to be terminated the outer loop is still active.

W.A.P to print 1 to 4 using break statement.

#include<stdio.h>
#include<conio.h>
void main()
 {    for(i=1; i<=10; i++)
  if(i==5)
  break;
 }
  printf(“%d\n”,i);
 }
  getch();
}

Output

 
1
2
3
4

continue

The continue statement in C language is used to bring the program control to the beginning of the loop. The continue statement skips some lines of code inside the loop and continues with the next iteration. It is mainly used for a condition so that we can skip some code for a particular condition.
Syntax:-
  while condition
 { 
  action 1;
  continue;
  action n;
 }

W.A.P to print 1 3 4 5

#include<stdio.h>
#include<conio.h>
void main()
{
 int i;
 {
 for( i=1;i<=5;i++)
 if(i==2)
 {
 continue;
 }
 printf(“%d”,i);
 }
 getch();
 }

Output

1
3
4
5