Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocumen...
If, Loop and Switch        Jithin Mathew        jitmat@gmail.com        www.facebook.com/jithinmatthew
Control Statement• Used in the C language to make decisions and  control the flow of the program.• It decide the flow of a...
They are decision making statements• If statement• If-else statement• Switch case
If StatementsSyntax:if (condition){  statement(s);}
#include <stdio.h>int main(){int num;printf("Enter a number to check.n");scanf("%d",&num);if(num>5)printf("numbur greater ...
If statement cont..• Adding a semicolon at the end of an ifclause is a common mistake.• This mistake is hard to find, beca...
if…else StatementSyntax: if(condition){ true statements;} else{false statements;}
Flow chart:
if...else Example#include <stdio.h>main(){   int no;   printf("n Enter Number :");   scanf("%d",&no);   if(no%2==0)       ...
switch Statement• This is a multiple or multiway brancing  decision making statement.• Similar to if statements• Can list ...
Switch flowchart                                          entry                                 Expression?value1      val...
#include <stdio.h>main(){     int no;     printf("Enter any number from 1 to 3 :");     scanf("%d",&no);     switch(no)   ...
Looping statement• It uses an expression that evaluates to either  TRUE or FALSE• Used to determine when an action should ...
while LoopIt repeatedly executes a target statement as long as agiven condition is true.   Syntax:  while(condition)      ...
Flow chart
#include <stdio.h>int main (){           /* local variable definition */  int a = 10;            /* while loop execution *...
do-while LoopSyntax;do { statements   }while (condition);
#include <stdio.h> int main (){        /* local variable definition */int a = 10;        /* do loop execution */do{ printf...
For Loop• It is a repetition control structure that allows  you to efficiently write a loop that needs to  execute a speci...
Syntax:for ( init; condition; increment ){statement(s);}
Flow chart:
for Loop Example#include <stdio.h>int main(){int a;for (a=0; a<5; a++){printf("Baabtran");}return 0;}
• If this presentation helped you, please visit  our page facebook.com/baabtra and like it.  Thanks in advance.• www.baabt...
Thank you
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
if,loop,switch
Upcoming SlideShare
Loading in …5
×

if,loop,switch

608
-1

Published on

3 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
608
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
3
Likes
2
Embeds 0
No embeds

No notes for slide

if,loop,switch

  1. 1. Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  2. 2. If, Loop and Switch Jithin Mathew jitmat@gmail.com www.facebook.com/jithinmatthew
  3. 3. Control Statement• Used in the C language to make decisions and control the flow of the program.• It decide the flow of a program.
  4. 4. They are decision making statements• If statement• If-else statement• Switch case
  5. 5. If StatementsSyntax:if (condition){ statement(s);}
  6. 6. #include <stdio.h>int main(){int num;printf("Enter a number to check.n");scanf("%d",&num);if(num>5)printf("numbur greater than 5");return 0;}
  7. 7. If statement cont..• Adding a semicolon at the end of an ifclause is a common mistake.• This mistake is hard to find, because it isnot a compilation error or a runtime error, itis a logic error.
  8. 8. if…else StatementSyntax: if(condition){ true statements;} else{false statements;}
  9. 9. Flow chart:
  10. 10. if...else Example#include <stdio.h>main(){ int no; printf("n Enter Number :"); scanf("%d",&no); if(no%2==0) printf("Number is even !"); else printf("nn Number is odd !"); return 0;}
  11. 11. switch Statement• This is a multiple or multiway brancing decision making statement.• Similar to if statements• Can list any number of branches• Used in place of nested if statements• Avoids confusion of deeply nested ifs• Easy to find out errors.
  12. 12. Switch flowchart entry Expression?value1 value2 value3 value4 Value n Statement(s) Statement(s) Statement(s) Statement(s) Statement(s)
  13. 13. #include <stdio.h>main(){ int no; printf("Enter any number from 1 to 3 :"); scanf("%d",&no); switch(no) { case 1: printf("It is 1 !"); break; case 2: printf("It is 2 !"); break; case 3: printf("It is 3 !"); break; default: printf("Invalid number !"); }getch();}
  14. 14. Looping statement• It uses an expression that evaluates to either TRUE or FALSE• Used to determine when an action should be repeatedly performed in a program. 1. do loop 2. while loop 3. for loop statements.
  15. 15. while LoopIt repeatedly executes a target statement as long as agiven condition is true. Syntax: while(condition) { statements; }
  16. 16. Flow chart
  17. 17. #include <stdio.h>int main (){ /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %dn", a); a++; } return 0;}
  18. 18. do-while LoopSyntax;do { statements }while (condition);
  19. 19. #include <stdio.h> int main (){ /* local variable definition */int a = 10; /* do loop execution */do{ printf("value of a: %dn", a);a = a + 1; }while( a < 20 );return 0;}
  20. 20. For Loop• It is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.• Easy to use• Highly flexible• More than one variable can be initilized.• More than one increments can be applied.
  21. 21. Syntax:for ( init; condition; increment ){statement(s);}
  22. 22. Flow chart:
  23. 23. for Loop Example#include <stdio.h>int main(){int a;for (a=0; a<5; a++){printf("Baabtran");}return 0;}
  24. 24. • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance.• www.baabtra.com | www.massbaab.com |ww w.baabte.com
  25. 25. Thank you
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×