SlideShare une entreprise Scribd logo
1  sur  57
A First Book of ANSI C Fourth Edition Chapter 5 Repetition
Objectives ,[object Object],[object Object],[object Object],[object Object]
Objectives (continued) ,[object Object],[object Object],[object Object],[object Object]
Introduction ,[object Object],[object Object]
Basic Loop Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pretest and Posttest Loops
Pretest and Posttest Loops (continued)
Counter-Controlled and  Condition-Controlled Loops ,[object Object],[object Object],[object Object]
Basic Loop Structures
The  while  Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  while  Statement (continued)
The  while  Statement (continued) Output is: 1 2 3 4 5 6 7 8 9 10
The  while  Statement (continued) Output is: 10 9 8 7 6 5 4 3 2 1
The  while  Statement (continued) Output is: NUMBER SQUARE CUBE ------ ------ ---- 1  1  1 2  4  8 3  9  27 4  16  64 5  25  125 6  36  216 7  49  343 8  64  512 9  81  729 10  100  1000
Condition-controlled loop Output is: DEGREES DEGREES CELSIUS FAHRENHEIT ------- ---------- 5  41.00 10  50.00 15  59.00 20  68.00 25  77.00 30  86.00 35  95.00 40  104.00 45  113.00 50  122.00 The  while  Statement (continued)
Computing Sums and Averages Using a  while  Loop
Computing Sums and Averages Using a  while  Loop (continued)
Computing Sums and Averages Using a  while  Loop (continued)
Computing Sums and Averages Using a  while  Loop (continued)
Ensures that any previous value present in the storage locations assigned to the variable  total  is overwritten and the  total  starts at a correct value Accumulating statement Computing Sums and Averages Using a  while  Loop (continued)
Calculating an average Computing Sums and Averages Using a  while  Loop (continued)
Sentinels ,[object Object],[object Object],[object Object],[object Object]
Sentinels (continued)
Sentinels (continued) ,[object Object],[object Object],[object Object]
Sentinels (continued)
Sentinels (continued)
The  break  and  continue  Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  break  and  continue  Statements (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Null Statement ,[object Object],[object Object],[object Object],[object Object]
The  for  Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  for  Statement (continued)
The  for  Statement (continued) ,[object Object],[object Object]
The  for  Statement (continued)
The  for  Statement (continued)
The  for  Statement (continued) Comma-separated  list
The  for  Statement (continued) (compare with Program 5.3)
Computing Sums and Averages Using a  for  Loop
Case Studies: Loop Programming Techniques ,[object Object],[object Object],[object Object],[object Object]
Technique 1: Selection within a Loop
Technique 2: Input Data Validation Same code used in lines 6-7!
Technique 2: Input Data Validation (continued)
Technique 3: Interactive Loop Control
Technique 4: Evaluating Equations
Technique 4: Evaluating Equations (continued)
Nested Loops
Nested Loops (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nested Loops (continued)
Nested Loops (continued)
The  do-while  Statement
The  do-while  Statement (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  do-while  Statement (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  do-while  Statement (continued)
Common Programming Errors ,[object Object],[object Object],[object Object]
Common Programming Errors (continued) ,[object Object],[object Object],[object Object]
Common Compiler Errors
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary (continued) ,[object Object],[object Object],[object Object]

Contenu connexe

Tendances

C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
Andrew Raj
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
Jomel Penalba
 
Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 

Tendances (18)

Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Looping
LoopingLooping
Looping
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
Ch3 Formatted Input/Output
Ch3 Formatted Input/OutputCh3 Formatted Input/Output
Ch3 Formatted Input/Output
 
Ch7 Basic Types
Ch7 Basic TypesCh7 Basic Types
Ch7 Basic Types
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
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
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
 

Similaire à Ch05

Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01
VincentAcapen1
 

Similaire à Ch05 (20)

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Loops c++
Loops c++Loops c++
Loops c++
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01Introductiontoflowchart 110630082600-phpapp01
Introductiontoflowchart 110630082600-phpapp01
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdf
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
What is c
What is cWhat is c
What is c
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and Testing
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Loops in c
Loops in cLoops in c
Loops in c
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
control statements
control statementscontrol statements
control statements
 

Plus de Arriz San Juan

Plus de Arriz San Juan (12)

Session 6 merchandising1
Session 6 merchandising1Session 6 merchandising1
Session 6 merchandising1
 
9. logic gates._rr
9. logic gates._rr9. logic gates._rr
9. logic gates._rr
 
7. kirchhoff s_rules
7. kirchhoff s_rules7. kirchhoff s_rules
7. kirchhoff s_rules
 
9. transistors.rr
9. transistors.rr9. transistors.rr
9. transistors.rr
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Chap 17 controlling
Chap 17 controllingChap 17 controlling
Chap 17 controlling
 
11 advance inheritance_concepts
11 advance inheritance_concepts11 advance inheritance_concepts
11 advance inheritance_concepts
 
9. transistors.rr
9. transistors.rr9. transistors.rr
9. transistors.rr
 
8. semiconductors.rr
8. semiconductors.rr8. semiconductors.rr
8. semiconductors.rr
 
7. kirchhoff s_rules
7. kirchhoff s_rules7. kirchhoff s_rules
7. kirchhoff s_rules
 
Ch07
Ch07Ch07
Ch07
 

Dernier

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Ch05