0% found this document useful (0 votes)
42 views8 pages

Cs112 - Programming Fundamental: Lecture # 16 - Jumping Statements in C Syed Shahrooz Shamim

This document discusses different types of jumping statements in C programming including break, continue, goto, return, and exit(). It provides examples of how to use break and continue statements to control loops. Break is used to terminate a loop entirely while continue skips the remaining code in the current loop iteration. Goto allows unconditional or conditional transfer of control to another part of the program. Return returns from a function, while exit() terminates the entire process.

Uploaded by

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

Cs112 - Programming Fundamental: Lecture # 16 - Jumping Statements in C Syed Shahrooz Shamim

This document discusses different types of jumping statements in C programming including break, continue, goto, return, and exit(). It provides examples of how to use break and continue statements to control loops. Break is used to terminate a loop entirely while continue skips the remaining code in the current loop iteration. Goto allows unconditional or conditional transfer of control to another part of the program. Return returns from a function, while exit() terminates the entire process.

Uploaded by

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

CS112 - PROGRAMMING FUNDAMENTAL

Lecture # 16 – Jumping Statements in C


Syed Shahrooz Shamim
Junior Lecturer,
CS Department, UIT
Jumping Statements
• Jumping statements are also known as Loop Control
Statements.
• Jumping statements are of different types
o break
o continue
o goto
o return
o exit ()
Break Statements
• Break statement simply terminates the loop and
takes control out of the loop. Here explained break
statement for for Loop

for(…………….) 8. Print sum of infinite numbers.


#include <stdio.h>
{
void main ()
.. . . . . . . .
{ int a, sum=0;
.. . . . . . . . for( ; ; )
if (condition) { scanf(“%d”, &a);
break; if (a==-999)
.. . . . . . . . break;
.. . . . . . . . sum=sum+a; }
} printf(“The sum is %d”, sum); }
Break Statement for while & do While Loop

while(……..) do
{ {
......... .........
......... .........
if (condition) if (condition)
break; break;
......... .........
......... .........}
} while (…….);
......... .........
......... .........
Continue Statement
• Continue is used for skipping a part of loop for
some condition.
• Continue causes the remaining code inside a loop
block to be skipped and causes execution of jump to
the top of loop block
12 Print 1-10 numbers except 3 and 7
for(…………….)
{ #include <stdio.h>
.. . . . . . . . void main ()
.. . . . . . . . {
if (condition) int i;
continue; for(i=1 ; 1<=10 ; i++)
.. . . . . . . . {
.. . . . . . . . if ((i==3)||(i==7))
} continue;
printf(“ %d\t”, i);
} }
Continue Statement for while & do-while Loops

while(……..) do
{ {
......... .........
......... .........
if (condition) if (condition)
continue;
continue;
.........
.........
.........}
.........
while (…….);
} .........
......... .........
.........
goto statement

• The goto statement is used to alter the


normal sequence of program execution goto label1
by transferring control to some other ..........
part of the program
unconditionally/conditionally. ..........
• In its general form, the goto statement is label2:
written as ..........
• goto label; ..........
• where the label is an identifier that is label1:
used to label the target statement to
which the control is transferred. ..........
label : statement; ..........
• Each labeled statement within the goto label2
function must have a unique label, i.e.,
no two statement can have the same
label.
return statement and exit()
• return is an instruction of the language that returns
from a function call.
• exit is a system call (not a language statement) that
terminates the current process.

You might also like