Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Control Structure in C

1.358 Aufrufe

Veröffentlicht am

This Presentation explains decision making statements of C language

Veröffentlicht in: Bildung
  • Als Erste(r) kommentieren

Control Structure in C

  1. 1. Made By: Neel Pradip Shah (13CP612) (130110107048) 1
  2. 2. There are some situations where one may have to  Change the order of execution based on certain conditions OR  Repeat a group of statements until certain conditions are satisfied. 2
  3. 3. For this, C supports some statements which are capable of decision making, they are: 1. If statement 2. Switch statement 3. Conditional Operator 4. Goto Statement 5. While loop 6. Do-While loop 7. For loop 3
  4. 4. Syntax if(test expression) { statement Block; } statement X; Test expression ? Statement - block Statement - X Next Statement TRUE FALSE ENTRY 4
  5. 5. Syntax if(test expression) { statement Block(true); } else { statement Block(false); } statement X; Test expression ? Statement - block Statement - X TRUE ENTRY Statement - block FALSE 5
  6. 6. Syntax switch(expression) { case value-1: block-1; break; case value-2: block-2; break; …………….. …………….. default block; break; } Statement - X 6
  7. 7.  It is used for an unconditional jump Syntax (forward jump) (backward jump) goto label; label: …………….. Statement; …………….. ……………… Label: ……………… Statement; goto label;  Programmers avoid using this  As this statement makes logic complicated and debugging is difficult. 7
  8. 8.  An Entry Controlled loop  Syntax while(test condition) { Body Of the Loop } 8
  9. 9.  An Exit Controlled loop  Syntax do { set of statements } while(condition); 9
  10. 10.  An Entry Controlled Loop  Syntax for(initialization ; test-condition ; increment) { BODY OF THE LOOP } 10
  11. 11. for(initialization ; test-condition ; increment) { BODY OF THE LOOP } 11
  12. 12. Entry True False Entry False True Test Condition Test Condition Body of The loop Body of The loop 12
  13. 13. a=10; for(a=10; a!=0; a--)a=10; for(a=10; a!=0; a--) while(a != 0)while(a != 0) {{ { printf(“%d”,a);{ printf(“%d”,a); }} printf(“%d”,a);printf(“%d”,a); a--;a--; }} a=10;a=10; dodo { OUTPUT : 10987654321{ OUTPUT : 10987654321 Printf(“%d”,a);Printf(“%d”,a); a--;a--; }} while(a!=0)while(a!=0) 13
  14. 14.  ANSI C By E.Balagurusamy  Programming With C By Byron S Gottfried 14
  15. 15. 15

×