SlideShare une entreprise Scribd logo
1  sur  35
Disclaimer:This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
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 program.
They are decision making statements

• If statement
• If-else statement
• Switch case
If Statements
Syntax:

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 than 5");

return 0;

}
If statement cont..
• Adding a semicolon at the end of an if
clause is a common mistake.
• This mistake is hard to find, because it is
not a compilation error or a runtime error, it
is a logic error.
if…else Statement
Syntax:
 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)
        printf("Number is even !");
   else
        printf("nn Number is odd !");
   return 0;
}
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.
Switch flowchart
                                          entry


                                 Expression?



value1      value2             value3             value4         Value n

 Statement(s)   Statement(s)     Statement(s)     Statement(s)   Statement(s)
#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();
}
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.
while Loop
It repeatedly executes a target statement as long as a
given condition is true.

   Syntax:
  while(condition)
         {
        statements;
         }
Flow chart
#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;
}
do-while Loop
Syntax;
do {
 statements
   }
while (condition);
#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;
}
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.
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.baabtra.com | www.massbaab.com |ww
  w.baabte.com
Thank you

Contenu connexe

Tendances

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danishMuhammed Thanveer M
 
Control structure of c language
Control structure of c languageControl structure of c language
Control structure of c languageDigvijaysinh Gohil
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or javaSamsil Arefin
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in cvampugani
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c languageshhanks
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 

Tendances (20)

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danish
 
Control structure of c language
Control structure of c languageControl structure of c language
Control structure of c language
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 
Control structure
Control structureControl structure
Control structure
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Branching in C
Branching in CBranching in C
Branching in C
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 

Similaire à if,loop,switch

Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptxDEEPAK948083
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxSmitaAparadh
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programmingnmahi96
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptxPrecise Mya
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 

Similaire à if,loop,switch (20)

Session 3
Session 3Session 3
Session 3
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
Lec 10
Lec 10Lec 10
Lec 10
 
Branching statements
Branching statementsBranching statements
Branching statements
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
3. control statement
3. control statement3. control statement
3. control statement
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptx
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 

Plus de baabtra.com - No. 1 supplier of quality freshers

Plus de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

if,loop,switch

  • 1.
  • 2. Disclaimer:This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. If, Loop and Switch Jithin Mathew jitmat@gmail.com www.facebook.com/jithinmatthew
  • 4. Control Statement • Used in the C language to make decisions and control the flow of the program. • It decide the flow of a program.
  • 5. They are decision making statements • If statement • If-else statement • Switch case
  • 7.
  • 8. #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; }
  • 9.
  • 10. If statement cont.. • Adding a semicolon at the end of an if clause is a common mistake. • This mistake is hard to find, because it is not a compilation error or a runtime error, it is a logic error.
  • 11. if…else Statement Syntax: if(condition) { true statements; } else { false statements; }
  • 13. 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; }
  • 14.
  • 15. 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.
  • 16.
  • 17. Switch flowchart entry Expression? value1 value2 value3 value4 Value n Statement(s) Statement(s) Statement(s) Statement(s) Statement(s)
  • 18. #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(); }
  • 19.
  • 20. 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.
  • 21. while Loop It repeatedly executes a target statement as long as a given condition is true. Syntax: while(condition) { statements; }
  • 23. #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; }
  • 24.
  • 25. do-while Loop Syntax; do { statements } while (condition);
  • 26.
  • 27. #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; }
  • 28.
  • 29. 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.
  • 30. Syntax: for ( init; condition; increment ) { statement(s); }
  • 32. for Loop Example #include <stdio.h> int main() { int a; for (a=0; a<5; a++) { printf("Baabtran"); } return 0; }
  • 33.
  • 34. • 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