Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Decision Making and

Branching – Looping
Statements

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 1


Control Statements

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 2


Single Way Decision: If

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 3


Two Way Decision: If-Else

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 4


Multi Way Decision-If-Else-If ladder

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 5


Nested if

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 6


Conditional Operator

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 7


The switch Statement

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 8


Iteration and Repetitive Execution

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 9


while Construct

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 10


do while Construct

#include <stdio.h>
int main()
{
int j=0;
do
{
printf("Value of variable j is: %d\n", j);
j++;
}while (j<=3);
return 0;
}

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 11


for Construct

#include<stdio.h>
int main()
{
int i=1,number=0;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=10;i++)
{
printf("%d \n",(number*i));
}
01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 12
break

The break statement provides an #include <stdio.h>


early exit from for, while, and do, int main()
{
just as from switch. int var;
A break causes the innermost for (var =100; var>=10; var --)
{
enclosing loop or switch to be printf("var: %d\n", var);
exited immediately. if (var==99)
{
break;
}
}
printf("Out of for-loop");
return 0;
}

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 13


continue

It causes the next iteration of the enclosing for, #include <stdio.h>
int main()
while, or do loop to begin.
{
In the while and do, this means that the test part is int counter=10;
while (counter >=0)
executed immediately; {
if (counter==7)
In the for, control passes to the increment step. {
counter--;
The continue statement applies only to loops, not continue;
to switch. }
printf("%d ", counter);
A continue inside a switch inside a loop causes the counter--;
next loop iteration. }
return 0;
}

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 14


// function to check even or not
goto void checkEvenOrNot(int num)
{
if (num % 2 == 0)
// jump to even
goto even;
Used for breaking out of two or more loops at once.
else
The break statement cannot be used directly since it only // jump to odd
exits from the innermost loop. goto odd;

even:
printf("%d is even", num);
// return if even
return;
odd:
printf("%d is odd", num);
}

int main() {
int num = 26;
checkEvenOrNot(num);
return 0;
}
01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 15
Write and share

Write a program in c to
print number 1 to 5 using
for loop statement?

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 16


Thank you

01/05/2021 S.SENTHILKUMAR ASSO.PROF/ECE,GRTIET 17

You might also like