SlideShare a Scribd company logo
CONTROL FLOW in C.pptx
Control Structure
• Decision Making Statements
Simple if
If else
Nested if else
Switch Statements (conditional branching)
• Loops
Do- while
While statements
For Statements
• Unconditional Branching
break statement
continue statement
goto statement
Given By Prof. Aparadh S.Y.
Simple if
• Syntax
Flow Diagram
if (expression is true)
{
action 1;
}
action 2;
action3;
Given By Prof. Aparadh S.Y.
Examples of Simple if
1. Print hello when number is 10
Given By Prof. Aparadh S.Y.
Examples of Simple if
1. Print hello when number is 10
Given By Prof. Aparadh S.Y.
#include<conio.h>
#include<stdio.h>
void main()
{
int num;
clrscr();
printf("Enter value for num“);
scanf(“%d”, &num);
if(num==10)
{
printf("hello)";
getch();
}
}
If Else
• Syntax
Flow Chart
if (expression is true)
{
action 1;
}
Else
{
action 2;
}
action3;
Given By Prof. Aparadh S.Y.
Examples of If Else
1. Print entered number is positive or negative
Given By Prof. Aparadh S.Y.
Examples of If Else
1. Print entered number is positive or negative
Given By Prof. Aparadh S.Y.
#include<conio.h>
#include<stdio.h>
void main()
{
int num;
clrscr();
printf(“Enter value for num“);
Scanf(“%d”,&num);
if(num>0)
{
Printf("num is positive“);
}
else
{
Printf("num is negative“)S;
}
getch();
}
Examples of If Else
1. Print entered number is even or odd
Given By Prof. Aparadh S.Y.
Examples of If Else
1. Print entered number is even or odd
Given By Prof. Aparadh S.Y.
#include<conio.h>
#include<stdio.h>
void main()
{
int num;
clrscr();
printf(“Enter value for num“);
Scanf(“%d”,&num);
if(num%2==0)
{
Printf("num is even“);
}
else
{
Printf("num is odd“)S;
}
getch();
}
Examples of If Else
1. Print entered year is leap year or not
Given By Prof. Aparadh S.Y.
Examples of If Else
1. Print entered year is leap year or not
Given By Prof. Aparadh S.Y.
#include<conio.h>
#include<stdio.h>
void main()
{
int num;
clrscr();
printf(“Enter value for year“);
Scanf(“%d”,&num);
if(num%4==0)
{
Printf(“year is leap year“);
}
else
{
Printf(“year is not leap year“)S;
}
getch();
}
Nested If Else Ladder
• Syntax
Flow Chart
Given By Prof. Aparadh S.Y.
Home Work of Nested
If Else
Given By Prof. Aparadh S.Y.
Write a program to input three numbers from user. Find maximum
between given three numbers.
Home Work of Nested If Else
Given By Prof. Aparadh S.Y.
Write a program to input three numbers from user. Find maximum between given three numbers.
#include<stdio.hh>
#include<conio.h>
void main()
{
int num1,num2,num3;
clrscr();
printf("Enter value for num1,num2 and num3“);
scanf(“%d%d%d”,&num1, &num2, &num3);
if(num1>num2)
{
if(num1>num3)
{
printf("num1 is greater“);
}
else
{
printf("num3 is greater“);
}
}
else
{
if(num2>num3)
{
printf("num2 is greater“);
}
else
{
printf(num3 is greater“);
}
}
getch();
}
 Output:
Enter value for num1 ,num2 and num3
4 2 1
Num1 is greater
 Output:
Enter value for num1 ,num2 and num3
1 4 2
Num2 is greater
 Output:
Enter value for num1 ,num2 and num3
1 2 3
Num3 is greater
If Else Ladder
Given By Prof. Aparadh S.Y.
In C,C++ if- else –if ladder helps user decide from among multiple
options .
Here if statements are executed from top down
As soon as one of the conditions controlling the if is true , the
statements associated with that if is executed, and rest of all conditions
are bypassed.
If none of the conditions is true then the final else statement will be
executed
If Else Ladder
• Syntax
Flow Chart
if (condition1)
{
statement 1;
}
else if (condition2)
{
statement 2;
}
.
.
else
{
statement;
}
Given By Prof. Aparadh S.Y.
Examples of If Else
1. Print entered number is positive, negative or zero.
Given By Prof. Aparadh S.Y.
Examples of If Else ladder
1. Print entered number is positive, negative or zero.
Given By Prof. Aparadh S.Y.
#include<stdio.hh>
#include<conio.h>
void main()
{
int num;
clrscr();
Printf(“Enter num“);
Scanf(“%d”, &num;
if(num>0)
{
Printf(“Positive“);
}
else if(num<0)
{
Printf(“Negative“);
}
else
{
Printf(“Zero“);
}
getch();
}
 Output:
Enter num
6
Positive
 Output:
Enter num
-3
Negative
 Output:
Enter num
0
Zero
Examples of If Else ladder
Write a program to calculate grade of students
Given By Prof. Aparadh S.Y.
Write a program to calculate grade of students
#include<iostream.h>
#include<conio.h>
void main()
{
int grade;
clrscr();
Printf("enter value grade“);
Scanf(“%d”, &grade);
if(grade>=70 && grade<=100)
{
Printf(“Distinction“);
}
else if(grade>=60 && grade<=69)
{
Printf("First Class“);
}
else if(grade>=45 && grade<=59)
{
Printf(“Second Class“);
}
Given By Prof. Aparadh S.Y.
else if(grade>=40 && grade<=44)
{
Printf("Pass Class“);
}
else if(grade>=0 && grade<40)
{
Printf("fail“);
}
else
{
Printf("invalid grade“);
Printf("nshould enter grade
inbetween 0 to 100“);
}
getch();
}
//Distinction grade>=70 &&
grade<=100
//First Class grade>=60 &&
grade<=69
//Second Class grade>=45 &&
grade<=59
//Pass Class grade>=40 &&
grade<=44
//Fail grade>=0 &&
grade <45
//Invalid grade>=100
&& grade<=0
Switch Statements
Syntax
Flow Chart
switch (expression)
{
case 1:
action 1;
break;
Case 2:
action 2;
break;
}
.
Case n:
action n;
break;
Default:
break;
}
Given By Prof. Aparadh S.Y.
1. Perform arithmetic operations using switch case
Examples Switch Case
Given By Prof. Aparadh S.Y.
1. .Perform arithmetic operations using switch case
Examples Switch Case
Given By Prof. Aparadh S.Y.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ch;
clrscr();
Printf("Enter value for a and b“);
Scanf(”%d%d”,&a,&b);
Printf("Enter choice“);
Scanf(“%d”,&ch)
switch(ch)
{
case 1:
scanf("Addition is=%d”, a+b);
break;
case 4:
scanf(“Division is=%d”, a/b);
break;
default:
printf("Enter valid choice“);
break;
}
getch();
}
case 2:
scanf(“Subtraction is=%d”, a-b);
break;
case 3:
scanf(“ Multiplication is=%d”, a*b);
break;
Do While Loop
• Syntax
Flow Diagram
Given By Prof. Aparadh S.Y.
do
{
action 1;
}
while(condition is true);
action 2;
Examples of Do While
Loop
1. Print 1 to 10 numbers using do while loop
Given By Prof. Aparadh S.Y.
Examples of Do While
Loop
1. Print 1 to 10 numbers using do while loop
Given By Prof. Aparadh
S.Y.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a=1;
Clrscr();
do
{
printf(“n%d”,a);
a++;
} while(a<=10);
getch();
}
Output:
1
2
3
4
5
6
7
8
9
10
Examples of Do While
Loop
1. Print 10 to 1 numbers using do while loop
Given By Prof. Aparadh
S.Y.
Examples of Do While
Loop
1. Print 10 to 1 numbers using do while loop
Given By Prof. Aparadh
S.Y.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a=10;
Clrscr();
do
{
printf(“n%d”,a);
a--;
} while(a>0);
getch();
}
Output:
10
9
8
7
6
5
4
3
2
1
• Syntax
Flow Chart
while (condition is true)
{
action 1;
}
action 2;
While Loop
Examples of While Loop
1. Print 1 to 10 numbers using while loop
Given By Prof. Aparadh
S.Y.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a=1;
Clrscr();
While(a<=10)
{
printf(“n%d”,a);
a++;
}
getch();
}
Output:
1
2
3
4
5
6
7
8
9
10
Examples of While Loop
1. Print 10 to 1 numbers using while loop
Given By Prof. Aparadh
S.Y.
Examples of While Loop
1. Print 10 to 1 numbers using while loop
Given By Prof. Aparadh
S.Y.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a=10;
Clrscr();
While(a>=10)
{
printf(“n%d”,a);
a--;
}
getch();
}
Output:
10
9
8
7
6
5
4
3
2
1
• Syntax
Flow Chart
for (initial value; condition; increment/decrement)
{
action 1;
}
action 2;
For Loop
Examples of for Loop
1. Print 10 to 1 numbers using for loop
Given By Prof. Aparadh
S.Y.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a;
Clrscr();
For(a=10;a>0;a--)
{
printf(“n%d”,a);
a--;
}
getch();
}
Output:
10
9
8
7
6
5
4
3
2
1
• Syntax
Flow Chart
for (initial value; condition; increment/decrement)
{
action 1;
For((initial value; condition; increment/decrement)
{
body of inner loop;
}
action 2;
}
Nesting For Loop
Examples of nesting for Loop
Given By Prof. Aparadh
S.Y.
Program to print following pattern using nested for loop
* * * * * *
* * * * * *
* * * * * *
* * * * * *
# include<stdio.h>
#include<conio.h>
Void main()
{
int I,j;
Clrscr();
For(j=1;j<=4;j++)
{
for(i=1;i<=5;i++)
{
printf(“*”);
}
printf(“n”);
}
getch();
}
Unconditional Branching
 It is also called as jumping
Control is transfer from one point to another without checking condition
goto statement
break statement
Continue
Break Statement
The break statement in C programming
has the following two usages −
•When a break statement is encountered
inside a loop, the loop is immediately
terminated and the program control
resumes at the next statement following the
loop.
•It can be used to terminate a case in
the switch statement (covered in the next
chapter).
If you are using nested loops, the break
statement will stop the execution of the
innermost loop and start executing the next
line of code after the block.
Syntax
The syntax for a break statement in C is as
follows −
break;
Flow Diagram
Break Statement
#include <stdio.h>
int main
{
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 )
{
printf("value of a: %dn", a);
a++;
if( a > 15)
{ /* terminate the loop using break
statement */
break;
}
}
return 0;
}
When the above code is compiled and
executed, it produces the following result
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
Continue Statement
The continue statement in C programming
works somewhat like the break statement.
Instead of forcing termination, it forces
the next iteration of the loop to take
place, skipping any code in between.
For the for loop, continue statement
causes the conditional test and increment
portions of the loop to execute.
For
the while and do...while loops, continue
statement causes the program control to
pass to the conditional tests.
Syntax
The syntax for a continue statement in C is
as follows −
continue;
Flow Diagram
Continue Statement
#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 10;
/* do loop execution */
do
{
if( a == 15)
{
/* skip the iteration */
a = a + 1;
continue;
}
printf("value of a: %dn", a);
a++;
} while( a < 20 );
return 0;
}
When the above code is compiled and
executed, it produces the following result
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Goto Statement
A goto statement in C programming
provides an unconditional jump from the
'goto' to a labeled statement in the same
function.
NOTE − Use of goto statement is highly
discouraged in any programming language
because it makes difficult to trace the
control flow of a program, making the
program hard to understand and hard to
modify. Any program that uses a goto can
be rewritten to avoid them.
Syntax
The syntax for a goto statement in C is as
follows −
goto label;
.. .
label: statement;
Flow Diagram
Continue Statement
#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 10;
/* do loop execution */
LOOP:do
{
if( a == 15)
{
/* skip the iteration */
a = a + 1;
goto LOOP;
}
printf("value of a: %dn", a);
a++;
}
while( a < 20 );
return 0;
}
When the above code is compiled and
executed, it produces the following result
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19

More Related Content

PDF
Unit ii chapter 2 Decision making and Branching in C
PPTX
computer programming Control Statements.pptx
PPTX
Control Structures in C
PPTX
Branching statements
PDF
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PPT
PPTX
unit 2-Control Structures.pptx
PPTX
C Programming: Control Structure
Unit ii chapter 2 Decision making and Branching in C
computer programming Control Statements.pptx
Control Structures in C
Branching statements
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
unit 2-Control Structures.pptx
C Programming: Control Structure

Similar to CONTROL FLOW in C.pptx (20)

PPTX
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
PPTX
C programming Control Structure.pptx
PPT
CONTROLSTRUCTURES.ppt
PDF
Fundamental of Information Technology - UNIT 8
PPTX
control_structures_c_language_regarding how to represent the loop in language...
PPTX
Control structure of c
PDF
Control structuresin c
PPTX
Condition Stmt n Looping stmt.pptx
PPTX
C Unit-2.ppt
PDF
control statement
PPTX
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PDF
POP Unit 2.pptx.pdf for your time and gauss with example
PPTX
C Programming Control Structures(if,if-else)
DOC
Slide07 repetitions
PPSX
Bsit1
PDF
Loop's definition and practical code in C programming
PPTX
Basics of Control Statement in C Languages
PPTX
Control Structures.pptx
PPTX
COM1407: Program Control Structures – Repetition and Loops
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
C programming Control Structure.pptx
CONTROLSTRUCTURES.ppt
Fundamental of Information Technology - UNIT 8
control_structures_c_language_regarding how to represent the loop in language...
Control structure of c
Control structuresin c
Condition Stmt n Looping stmt.pptx
C Unit-2.ppt
control statement
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
POP Unit 2.pptx.pdf for your time and gauss with example
C Programming Control Structures(if,if-else)
Slide07 repetitions
Bsit1
Loop's definition and practical code in C programming
Basics of Control Statement in C Languages
Control Structures.pptx
COM1407: Program Control Structures – Repetition and Loops
Ad

Recently uploaded (20)

PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
web development for engineering and engineering
PPTX
additive manufacturing of ss316l using mig welding
DOCX
573137875-Attendance-Management-System-original
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Lecture Notes Electrical Wiring System Components
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
OOP with Java - Java Introduction (Basics)
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
bas. eng. economics group 4 presentation 1.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Automation-in-Manufacturing-Chapter-Introduction.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT 4 Total Quality Management .pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
web development for engineering and engineering
additive manufacturing of ss316l using mig welding
573137875-Attendance-Management-System-original
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Lecture Notes Electrical Wiring System Components
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Embodied AI: Ushering in the Next Era of Intelligent Systems
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Ad

CONTROL FLOW in C.pptx

  • 2. Control Structure • Decision Making Statements Simple if If else Nested if else Switch Statements (conditional branching) • Loops Do- while While statements For Statements • Unconditional Branching break statement continue statement goto statement Given By Prof. Aparadh S.Y.
  • 3. Simple if • Syntax Flow Diagram if (expression is true) { action 1; } action 2; action3; Given By Prof. Aparadh S.Y.
  • 4. Examples of Simple if 1. Print hello when number is 10 Given By Prof. Aparadh S.Y.
  • 5. Examples of Simple if 1. Print hello when number is 10 Given By Prof. Aparadh S.Y. #include<conio.h> #include<stdio.h> void main() { int num; clrscr(); printf("Enter value for num“); scanf(“%d”, &num); if(num==10) { printf("hello)"; getch(); } }
  • 6. If Else • Syntax Flow Chart if (expression is true) { action 1; } Else { action 2; } action3; Given By Prof. Aparadh S.Y.
  • 7. Examples of If Else 1. Print entered number is positive or negative Given By Prof. Aparadh S.Y.
  • 8. Examples of If Else 1. Print entered number is positive or negative Given By Prof. Aparadh S.Y. #include<conio.h> #include<stdio.h> void main() { int num; clrscr(); printf(“Enter value for num“); Scanf(“%d”,&num); if(num>0) { Printf("num is positive“); } else { Printf("num is negative“)S; } getch(); }
  • 9. Examples of If Else 1. Print entered number is even or odd Given By Prof. Aparadh S.Y.
  • 10. Examples of If Else 1. Print entered number is even or odd Given By Prof. Aparadh S.Y. #include<conio.h> #include<stdio.h> void main() { int num; clrscr(); printf(“Enter value for num“); Scanf(“%d”,&num); if(num%2==0) { Printf("num is even“); } else { Printf("num is odd“)S; } getch(); }
  • 11. Examples of If Else 1. Print entered year is leap year or not Given By Prof. Aparadh S.Y.
  • 12. Examples of If Else 1. Print entered year is leap year or not Given By Prof. Aparadh S.Y. #include<conio.h> #include<stdio.h> void main() { int num; clrscr(); printf(“Enter value for year“); Scanf(“%d”,&num); if(num%4==0) { Printf(“year is leap year“); } else { Printf(“year is not leap year“)S; } getch(); }
  • 13. Nested If Else Ladder • Syntax Flow Chart Given By Prof. Aparadh S.Y.
  • 14. Home Work of Nested If Else Given By Prof. Aparadh S.Y. Write a program to input three numbers from user. Find maximum between given three numbers.
  • 15. Home Work of Nested If Else Given By Prof. Aparadh S.Y. Write a program to input three numbers from user. Find maximum between given three numbers. #include<stdio.hh> #include<conio.h> void main() { int num1,num2,num3; clrscr(); printf("Enter value for num1,num2 and num3“); scanf(“%d%d%d”,&num1, &num2, &num3); if(num1>num2) { if(num1>num3) { printf("num1 is greater“); } else { printf("num3 is greater“); } } else { if(num2>num3) { printf("num2 is greater“); } else { printf(num3 is greater“); } } getch(); }  Output: Enter value for num1 ,num2 and num3 4 2 1 Num1 is greater  Output: Enter value for num1 ,num2 and num3 1 4 2 Num2 is greater  Output: Enter value for num1 ,num2 and num3 1 2 3 Num3 is greater
  • 16. If Else Ladder Given By Prof. Aparadh S.Y. In C,C++ if- else –if ladder helps user decide from among multiple options . Here if statements are executed from top down As soon as one of the conditions controlling the if is true , the statements associated with that if is executed, and rest of all conditions are bypassed. If none of the conditions is true then the final else statement will be executed
  • 17. If Else Ladder • Syntax Flow Chart if (condition1) { statement 1; } else if (condition2) { statement 2; } . . else { statement; } Given By Prof. Aparadh S.Y.
  • 18. Examples of If Else 1. Print entered number is positive, negative or zero. Given By Prof. Aparadh S.Y.
  • 19. Examples of If Else ladder 1. Print entered number is positive, negative or zero. Given By Prof. Aparadh S.Y. #include<stdio.hh> #include<conio.h> void main() { int num; clrscr(); Printf(“Enter num“); Scanf(“%d”, &num; if(num>0) { Printf(“Positive“); } else if(num<0) { Printf(“Negative“); } else { Printf(“Zero“); } getch(); }  Output: Enter num 6 Positive  Output: Enter num -3 Negative  Output: Enter num 0 Zero
  • 20. Examples of If Else ladder Write a program to calculate grade of students Given By Prof. Aparadh S.Y.
  • 21. Write a program to calculate grade of students #include<iostream.h> #include<conio.h> void main() { int grade; clrscr(); Printf("enter value grade“); Scanf(“%d”, &grade); if(grade>=70 && grade<=100) { Printf(“Distinction“); } else if(grade>=60 && grade<=69) { Printf("First Class“); } else if(grade>=45 && grade<=59) { Printf(“Second Class“); } Given By Prof. Aparadh S.Y. else if(grade>=40 && grade<=44) { Printf("Pass Class“); } else if(grade>=0 && grade<40) { Printf("fail“); } else { Printf("invalid grade“); Printf("nshould enter grade inbetween 0 to 100“); } getch(); } //Distinction grade>=70 && grade<=100 //First Class grade>=60 && grade<=69 //Second Class grade>=45 && grade<=59 //Pass Class grade>=40 && grade<=44 //Fail grade>=0 && grade <45 //Invalid grade>=100 && grade<=0
  • 22. Switch Statements Syntax Flow Chart switch (expression) { case 1: action 1; break; Case 2: action 2; break; } . Case n: action n; break; Default: break; } Given By Prof. Aparadh S.Y.
  • 23. 1. Perform arithmetic operations using switch case Examples Switch Case Given By Prof. Aparadh S.Y.
  • 24. 1. .Perform arithmetic operations using switch case Examples Switch Case Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> void main() { int a,b,ch; clrscr(); Printf("Enter value for a and b“); Scanf(”%d%d”,&a,&b); Printf("Enter choice“); Scanf(“%d”,&ch) switch(ch) { case 1: scanf("Addition is=%d”, a+b); break; case 4: scanf(“Division is=%d”, a/b); break; default: printf("Enter valid choice“); break; } getch(); } case 2: scanf(“Subtraction is=%d”, a-b); break; case 3: scanf(“ Multiplication is=%d”, a*b); break;
  • 25. Do While Loop • Syntax Flow Diagram Given By Prof. Aparadh S.Y. do { action 1; } while(condition is true); action 2;
  • 26. Examples of Do While Loop 1. Print 1 to 10 numbers using do while loop Given By Prof. Aparadh S.Y.
  • 27. Examples of Do While Loop 1. Print 1 to 10 numbers using do while loop Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> Void main() { int a=1; Clrscr(); do { printf(“n%d”,a); a++; } while(a<=10); getch(); } Output: 1 2 3 4 5 6 7 8 9 10
  • 28. Examples of Do While Loop 1. Print 10 to 1 numbers using do while loop Given By Prof. Aparadh S.Y.
  • 29. Examples of Do While Loop 1. Print 10 to 1 numbers using do while loop Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> Void main() { int a=10; Clrscr(); do { printf(“n%d”,a); a--; } while(a>0); getch(); } Output: 10 9 8 7 6 5 4 3 2 1
  • 30. • Syntax Flow Chart while (condition is true) { action 1; } action 2; While Loop
  • 31. Examples of While Loop 1. Print 1 to 10 numbers using while loop Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> Void main() { int a=1; Clrscr(); While(a<=10) { printf(“n%d”,a); a++; } getch(); } Output: 1 2 3 4 5 6 7 8 9 10
  • 32. Examples of While Loop 1. Print 10 to 1 numbers using while loop Given By Prof. Aparadh S.Y.
  • 33. Examples of While Loop 1. Print 10 to 1 numbers using while loop Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> Void main() { int a=10; Clrscr(); While(a>=10) { printf(“n%d”,a); a--; } getch(); } Output: 10 9 8 7 6 5 4 3 2 1
  • 34. • Syntax Flow Chart for (initial value; condition; increment/decrement) { action 1; } action 2; For Loop
  • 35. Examples of for Loop 1. Print 10 to 1 numbers using for loop Given By Prof. Aparadh S.Y. #include<stdio.h> #include<conio.h> Void main() { int a; Clrscr(); For(a=10;a>0;a--) { printf(“n%d”,a); a--; } getch(); } Output: 10 9 8 7 6 5 4 3 2 1
  • 36. • Syntax Flow Chart for (initial value; condition; increment/decrement) { action 1; For((initial value; condition; increment/decrement) { body of inner loop; } action 2; } Nesting For Loop
  • 37. Examples of nesting for Loop Given By Prof. Aparadh S.Y. Program to print following pattern using nested for loop * * * * * * * * * * * * * * * * * * * * * * * * # include<stdio.h> #include<conio.h> Void main() { int I,j; Clrscr(); For(j=1;j<=4;j++) { for(i=1;i<=5;i++) { printf(“*”); } printf(“n”); } getch(); }
  • 38. Unconditional Branching  It is also called as jumping Control is transfer from one point to another without checking condition goto statement break statement Continue
  • 39. Break Statement The break statement in C programming has the following two usages − •When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. •It can be used to terminate a case in the switch statement (covered in the next chapter). If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block. Syntax The syntax for a break statement in C is as follows − break; Flow Diagram
  • 40. Break Statement #include <stdio.h> int main { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %dn", a); a++; if( a > 15) { /* terminate the loop using break statement */ break; } } return 0; } When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15
  • 41. Continue Statement The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests. Syntax The syntax for a continue statement in C is as follows − continue; Flow Diagram
  • 42. Continue Statement #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* do loop execution */ do { if( a == 15) { /* skip the iteration */ a = a + 1; continue; } printf("value of a: %dn", a); a++; } while( a < 20 ); return 0; } When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 43. Goto Statement A goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function. NOTE − Use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them. Syntax The syntax for a goto statement in C is as follows − goto label; .. . label: statement; Flow Diagram
  • 44. Continue Statement #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* do loop execution */ LOOP:do { if( a == 15) { /* skip the iteration */ a = a + 1; goto LOOP; } printf("value of a: %dn", a); a++; } while( a < 20 ); return 0; } When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19