• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
27
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. CONTROL CONSTRUCTS
  • 2. Control Constructs Control constructs are of two types 1. DECISION MAKING STATEMENTS 2.LOOPING STATEMENTS
  • 3. Control constructs are Decision making statements 1. If statement 2.If else statement 3. Nested if else statement 4.Switch case Looping statements 5.For loop 6.While loop 7.Do while loop
  • 4. If statement: if (condition) statement; or if (condition) { compound statement; }
  • 5. Example of if statement: int i; printf ("Type in an integer"); scanf ("%ld", &i); if (i == 0) { printf ("The number was zero"); } if (i > 0) { printf ("The number was positive"); } if (i < 0) { printf ("The number was negative"); }
  • 6. If else statement: if (condition) statement1; Else statement2; Or if (condition) { statements1 ; } Else { statements2 ; } If - else ? else if
  • 7. Example of if-else statement: int i; scanf ("%d",i); if (i > 0) { printf ("That number was positive!"); } else { printf ("That number was negative or zero!"); }
  • 8. Nested if else statement: if ((cond.) && (cond.)) { statement; } OR if (cond.) { if (cond.) { statement; } }
  • 9. Example of nested-if statement: if ((i > 2) && (i < 4)) { printf ("i is three"); } or: if (i > 2) { if (i < 4) { printf ("i is three"); } }
  • 10. SWITCH & BREAK switch (integer value) { case 1: statement1; break; /* optional line */ case 2: statement2; break; /* optional line */ .... default: default statement break; /* optional line */ } Switch case statement: