0% found this document useful (0 votes)
27 views

Unconditional Execution

The document discusses control flow statements in C programming including break, continue, and goto. It provides examples of using goto to alter the normal sequential execution of a program by transferring control to elsewhere. Specifically, it demonstrates both backward jumps when the label is before the goto statement, creating a loop, and forward jumps when the label is after to skip statements.

Uploaded by

Yuvaraj S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Unconditional Execution

The document discusses control flow statements in C programming including break, continue, and goto. It provides examples of using goto to alter the normal sequential execution of a program by transferring control to elsewhere. Specifically, it demonstrates both backward jumps when the label is before the goto statement, creating a loop, and forward jumps when the label is after to skip statements.

Uploaded by

Yuvaraj S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

 The flow of execution is transferred from one

part of a program to another part without


carrying out any conditional test.
 C supports
◦ break statement
◦ continue statement
◦ goto construct

break & continue Statements, goto


Constructs
• Format:
label:
{
statement;
}
.
.
.
goto label;
where label is an identifier and not a number.
 In C programming, goto statement is used for altering the
normal sequence of program execution by transferring control
to some other part of the program.
 The goto require a label in order to identify the place where the
branch is to be made
 A label is any valid variable name and must be followed by a
colon
 The label is placed immediately before the statement where to
control is to be transferred
 The label: can be anywhere in the program either before or after
the goto label; statement.
 goto breaks the normal sequential execution of
the program
 Backward Jump: If the label: is before the
statement goto label; a loop will be formed and
some statements will be executed repeatedly
 Forward Jump: if the label: is placed after the
goto label; some statement will be skipped
#include<stdio.h>
main()
{
int i=1;
bc:
if(i>5)
goto ab;
printf(“%d”,i);
i++;
goto bc;
ab:
{
printf(“%d’,i);
}
}
#include<stdio.h>
void main()
{
int a,sum=0,A;
printf("Enter a number");
A:
scanf("%d",&A);
if(A<=10)
{
sum=sum+A;
goto A;
}
printf("%d",sum);
}
#include<stdio.h>
void main()
{
int number;
printf(“ WWW. ");
goto x;
y:
printf(“ Expert");
goto z;
x:
printf("C Programming");
goto y;
z:
printf(".com");
}
#include<stdio.h>
#include<math.h>
main()
{
double x,y;
read:
scanf("%f", &x);
if (x < 0)
goto read;
y = sqrt(x);
printf("%f %f\n", x, y);
goto read;
}

You might also like