🗊Презентация Programming logic and design seventh edition. Chapter 5. Looping

Нажмите для полного просмотра!
Programming logic and design seventh edition. Chapter 5. Looping, слайд №1Programming logic and design seventh edition. Chapter 5. Looping, слайд №2Programming logic and design seventh edition. Chapter 5. Looping, слайд №3Programming logic and design seventh edition. Chapter 5. Looping, слайд №4Programming logic and design seventh edition. Chapter 5. Looping, слайд №5Programming logic and design seventh edition. Chapter 5. Looping, слайд №6Programming logic and design seventh edition. Chapter 5. Looping, слайд №7Programming logic and design seventh edition. Chapter 5. Looping, слайд №8Programming logic and design seventh edition. Chapter 5. Looping, слайд №9Programming logic and design seventh edition. Chapter 5. Looping, слайд №10Programming logic and design seventh edition. Chapter 5. Looping, слайд №11Programming logic and design seventh edition. Chapter 5. Looping, слайд №12Programming logic and design seventh edition. Chapter 5. Looping, слайд №13Programming logic and design seventh edition. Chapter 5. Looping, слайд №14Programming logic and design seventh edition. Chapter 5. Looping, слайд №15Programming logic and design seventh edition. Chapter 5. Looping, слайд №16Programming logic and design seventh edition. Chapter 5. Looping, слайд №17Programming logic and design seventh edition. Chapter 5. Looping, слайд №18Programming logic and design seventh edition. Chapter 5. Looping, слайд №19Programming logic and design seventh edition. Chapter 5. Looping, слайд №20Programming logic and design seventh edition. Chapter 5. Looping, слайд №21Programming logic and design seventh edition. Chapter 5. Looping, слайд №22Programming logic and design seventh edition. Chapter 5. Looping, слайд №23Programming logic and design seventh edition. Chapter 5. Looping, слайд №24Programming logic and design seventh edition. Chapter 5. Looping, слайд №25Programming logic and design seventh edition. Chapter 5. Looping, слайд №26Programming logic and design seventh edition. Chapter 5. Looping, слайд №27Programming logic and design seventh edition. Chapter 5. Looping, слайд №28Programming logic and design seventh edition. Chapter 5. Looping, слайд №29Programming logic and design seventh edition. Chapter 5. Looping, слайд №30Programming logic and design seventh edition. Chapter 5. Looping, слайд №31Programming logic and design seventh edition. Chapter 5. Looping, слайд №32Programming logic and design seventh edition. Chapter 5. Looping, слайд №33Programming logic and design seventh edition. Chapter 5. Looping, слайд №34Programming logic and design seventh edition. Chapter 5. Looping, слайд №35Programming logic and design seventh edition. Chapter 5. Looping, слайд №36Programming logic and design seventh edition. Chapter 5. Looping, слайд №37Programming logic and design seventh edition. Chapter 5. Looping, слайд №38

Вы можете ознакомиться и скачать презентацию на тему Programming logic and design seventh edition. Chapter 5. Looping. Доклад-сообщение содержит 38 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Programming Logic and Design
Seventh Edition
Chapter 5
Looping
Описание слайда:
Programming Logic and Design Seventh Edition Chapter 5 Looping

Слайд 2





Objectives
In this chapter, you will learn about:
The advantages of looping
Using a loop control variable
Nested loops
Avoiding common loop mistakes
Using a for loop
Common loop applications
Описание слайда:
Objectives In this chapter, you will learn about: The advantages of looping Using a loop control variable Nested loops Avoiding common loop mistakes Using a for loop Common loop applications

Слайд 3





Understanding the Advantages of Looping
Looping makes computer programming efficient and worthwhile
Write one set of instructions to operate on multiple, separate sets of data
Loop: a structure that repeats actions while some condition continues
Описание слайда:
Understanding the Advantages of Looping Looping makes computer programming efficient and worthwhile Write one set of instructions to operate on multiple, separate sets of data Loop: a structure that repeats actions while some condition continues

Слайд 4





Understanding the Advantages of Looping (continued)
Описание слайда:
Understanding the Advantages of Looping (continued)

Слайд 5





Using a Loop Control Variable
As long as a condition remains true, the statements in a while loop’s body execute
Control number of repetitions 
Loop control variable initialized before entering loop
Loop control variable tested
Body of loop must alter value of loop control variable
Repetitions controlled by:
Counter
Sentinel value
Описание слайда:
Using a Loop Control Variable As long as a condition remains true, the statements in a while loop’s body execute Control number of repetitions Loop control variable initialized before entering loop Loop control variable tested Body of loop must alter value of loop control variable Repetitions controlled by: Counter Sentinel value

Слайд 6





Using a Definite Loop 
with a Counter
Definite loop
Executes a predetermined number of times
Counter-controlled loop
Program counts loop repetitions
Loop control variables altered by:
Incrementing
Decrementing
Описание слайда:
Using a Definite Loop with a Counter Definite loop Executes a predetermined number of times Counter-controlled loop Program counts loop repetitions Loop control variables altered by: Incrementing Decrementing

Слайд 7


Programming logic and design seventh edition. Chapter 5. Looping, слайд №7
Описание слайда:

Слайд 8





Using an Indefinite Loop 
with a Sentinel Value
Indefinite loop
Performed a different number of times each time the program executes
The user decides how many times the loop executes
Описание слайда:
Using an Indefinite Loop with a Sentinel Value Indefinite loop Performed a different number of times each time the program executes The user decides how many times the loop executes

Слайд 9


Programming logic and design seventh edition. Chapter 5. Looping, слайд №9
Описание слайда:

Слайд 10





Understanding the Loop in a Program’s Mainline Logic
Three steps should occur in every properly functioning loop
Provide a starting value for the variable that will control the loop
Test the loop control variable to determine whether the loop body executes
Alter the loop control variable
Описание слайда:
Understanding the Loop in a Program’s Mainline Logic Three steps should occur in every properly functioning loop Provide a starting value for the variable that will control the loop Test the loop control variable to determine whether the loop body executes Alter the loop control variable

Слайд 11





Nested Loops
Nested loops: loops within loops
Outer loop: the loop that contains the other loop
Inner loop: the loop that is contained
Needed when values of two (or more) variables repeat to produce every combination of values
Описание слайда:
Nested Loops Nested loops: loops within loops Outer loop: the loop that contains the other loop Inner loop: the loop that is contained Needed when values of two (or more) variables repeat to produce every combination of values

Слайд 12





Nested Loops (continued)
Описание слайда:
Nested Loops (continued)

Слайд 13





Avoiding Common Loop Mistakes
Mistake: neglecting to initialize the loop control variable
Example: get name statement removed
Value of name unknown or garbage
Program may end before any labels printed
100 labels printed with an invalid name
Описание слайда:
Avoiding Common Loop Mistakes Mistake: neglecting to initialize the loop control variable Example: get name statement removed Value of name unknown or garbage Program may end before any labels printed 100 labels printed with an invalid name

Слайд 14


Programming logic and design seventh edition. Chapter 5. Looping, слайд №14
Описание слайда:

Слайд 15





Avoiding Common Loop Mistakes (continued)
Mistake: neglecting to alter the loop control variable
Remove get name instruction from outer loop
User never enters a name after the first one
Inner loop executes infinitely
Always incorrect to create a loop that cannot terminate
Описание слайда:
Avoiding Common Loop Mistakes (continued) Mistake: neglecting to alter the loop control variable Remove get name instruction from outer loop User never enters a name after the first one Inner loop executes infinitely Always incorrect to create a loop that cannot terminate

Слайд 16


Programming logic and design seventh edition. Chapter 5. Looping, слайд №16
Описание слайда:

Слайд 17





Avoiding Common Loop Mistakes (continued)
Mistake: using the wrong comparison with the loop control variable
Programmers must use correct comparison
Seriousness depends on actions performed within a loop
Overcharge insurance customer by one month
Overbook a flight on airline application 
Dispense extra medication to patients in pharmacy
Описание слайда:
Avoiding Common Loop Mistakes (continued) Mistake: using the wrong comparison with the loop control variable Programmers must use correct comparison Seriousness depends on actions performed within a loop Overcharge insurance customer by one month Overbook a flight on airline application Dispense extra medication to patients in pharmacy

Слайд 18





Figure 5-12 Incorrect logic for greeting program because the wrong test is made with the loop control variable
Figure 5-12 Incorrect logic for greeting program because the wrong test is made with the loop control variable
Описание слайда:
Figure 5-12 Incorrect logic for greeting program because the wrong test is made with the loop control variable Figure 5-12 Incorrect logic for greeting program because the wrong test is made with the loop control variable

Слайд 19





Avoiding Common Loop Mistakes (continued)
Mistake: including statements inside the loop that belong outside the loop
Example: discount every item by 30 percent
Inefficient because the same value is calculated 100 separate times for each price that is entered
Move outside the loop for efficiency
Описание слайда:
Avoiding Common Loop Mistakes (continued) Mistake: including statements inside the loop that belong outside the loop Example: discount every item by 30 percent Inefficient because the same value is calculated 100 separate times for each price that is entered Move outside the loop for efficiency

Слайд 20


Programming logic and design seventh edition. Chapter 5. Looping, слайд №20
Описание слайда:

Слайд 21


Programming logic and design seventh edition. Chapter 5. Looping, слайд №21
Описание слайда:

Слайд 22





Using a for Loop
for statement or for loop is a definite loop
Provides three actions in one structure
Initializes
Evaluates
Alters
Takes the form:
	for loopControlVariable = initialValue to finalValue step stepValue
		do something
	endfor
Описание слайда:
Using a for Loop for statement or for loop is a definite loop Provides three actions in one structure Initializes Evaluates Alters Takes the form: for loopControlVariable = initialValue to finalValue step stepValue do something endfor

Слайд 23





Using a for Loop (continued)
Example
for count = 0 to 3 step 1
		output "Hello"
endfor
Initializes count variable to 0
Checks count variable against the limit value 3
If evaluation is true, for statement body prints the word “Hello”
Increases count by 1
Описание слайда:
Using a for Loop (continued) Example for count = 0 to 3 step 1 output "Hello" endfor Initializes count variable to 0 Checks count variable against the limit value 3 If evaluation is true, for statement body prints the word “Hello” Increases count by 1

Слайд 24





Using a for Loop (continued)
while statement could be used in place of for statement
Step value: the amount by which a loop control variable changes
Can be positive or negative (incrementing or decrementing the loop control variable)
Default step value is 1
Programmer specifies a step value when each pass through the loop changes the loop control variable by a value other than 1
Описание слайда:
Using a for Loop (continued) while statement could be used in place of for statement Step value: the amount by which a loop control variable changes Can be positive or negative (incrementing or decrementing the loop control variable) Default step value is 1 Programmer specifies a step value when each pass through the loop changes the loop control variable by a value other than 1

Слайд 25





Using a for Loop (continued)
Pretest loop: the loop control variable is tested before each iteration
for loops and while loops are pretest loops
Posttest loop: the loop control variable is tested after each iteration
do…while is a posttest loop
Описание слайда:
Using a for Loop (continued) Pretest loop: the loop control variable is tested before each iteration for loops and while loops are pretest loops Posttest loop: the loop control variable is tested after each iteration do…while is a posttest loop

Слайд 26





Common Loop Applications
Using a loop to accumulate totals
Examples
Business reports often include totals
List of real estate sold and total value
Accumulator: variable that gathers values
Similar to a counter
Counter increments by 1
Accumulator increments by some value
Описание слайда:
Common Loop Applications Using a loop to accumulate totals Examples Business reports often include totals List of real estate sold and total value Accumulator: variable that gathers values Similar to a counter Counter increments by 1 Accumulator increments by some value

Слайд 27





Common Loop Applications (continued)
Accumulators require three actions
Initialize the accumulator to 0
Accumulators are altered: once for every data set processed
At the end of processing, accumulators are output
Summary reports
Contain only totals with no detail data
Loops are processed but detail information is not printed
Описание слайда:
Common Loop Applications (continued) Accumulators require three actions Initialize the accumulator to 0 Accumulators are altered: once for every data set processed At the end of processing, accumulators are output Summary reports Contain only totals with no detail data Loops are processed but detail information is not printed

Слайд 28





Common Loop Applications (continued)
Описание слайда:
Common Loop Applications (continued)

Слайд 29


Programming logic and design seventh edition. Chapter 5. Looping, слайд №29
Описание слайда:

Слайд 30





Using a loop to validate data
Using a loop to validate data
Defensive programming: preparing for all possible errors before they occur
When prompting a user for data, no guarantee that data is valid
Validate data: make sure data falls in acceptable ranges (month values between 1 and 12)
GIGO: Garbage in, garbage out
Unvalidated input will result in erroneous output
Описание слайда:
Using a loop to validate data Using a loop to validate data Defensive programming: preparing for all possible errors before they occur When prompting a user for data, no guarantee that data is valid Validate data: make sure data falls in acceptable ranges (month values between 1 and 12) GIGO: Garbage in, garbage out Unvalidated input will result in erroneous output

Слайд 31


Programming logic and design seventh edition. Chapter 5. Looping, слайд №31
Описание слайда:

Слайд 32


Programming logic and design seventh edition. Chapter 5. Looping, слайд №32
Описание слайда:

Слайд 33





Common Loop Applications (continued)
Limiting a reprompting loop
Reprompting can be frustrating to a user if it continues indefinitely
Maintain a count of the number of reprompts
Forcing a data item means: 
Override incorrect data by setting the variable to a specific value
Описание слайда:
Common Loop Applications (continued) Limiting a reprompting loop Reprompting can be frustrating to a user if it continues indefinitely Maintain a count of the number of reprompts Forcing a data item means: Override incorrect data by setting the variable to a specific value

Слайд 34





Common Loop Applications (continued)
Validating a data type
Validating data requires a variety of methods
isNumeric() or similar method
Provided with the language translator you use to write your programs
Black box
isChar() or isWhitespace()
Accept user data as strings
Use built-in methods to convert to correct data types
Описание слайда:
Common Loop Applications (continued) Validating a data type Validating data requires a variety of methods isNumeric() or similar method Provided with the language translator you use to write your programs Black box isChar() or isWhitespace() Accept user data as strings Use built-in methods to convert to correct data types

Слайд 35





Common Loop Applications (continued)
Figure 5-21 Checking data for correct type
Описание слайда:
Common Loop Applications (continued) Figure 5-21 Checking data for correct type

Слайд 36





Common Loop Applications (continued)
Validating reasonableness and consistency of data
Many data items can be checked for reasonableness
Good defensive programs try to foresee all possible inconsistencies and errors
Описание слайда:
Common Loop Applications (continued) Validating reasonableness and consistency of data Many data items can be checked for reasonableness Good defensive programs try to foresee all possible inconsistencies and errors

Слайд 37





Summary
Loops write one set of instructions that operate on multiple, separate sets of data
Three steps must occur in every loop
Initialize the loop control variable
Compare the variable to some value
Alter the variable that controls the loop
Nested loops: loops within loops
Nested loops maintain two individual loop control variables
Alter each at the appropriate time
Описание слайда:
Summary Loops write one set of instructions that operate on multiple, separate sets of data Three steps must occur in every loop Initialize the loop control variable Compare the variable to some value Alter the variable that controls the loop Nested loops: loops within loops Nested loops maintain two individual loop control variables Alter each at the appropriate time

Слайд 38





Summary (continued)
Common mistakes made by programmers
Neglecting to initialize the loop control variable
Neglecting to alter the loop control variable
Using the wrong comparison with the loop control variable
Including statements inside the loop that belong outside the loop
Most computer languages support a for statement
for loop used when the number of iterations is known
Loops are used to accumulate totals in business reports and to reprompt users for valid data
Описание слайда:
Summary (continued) Common mistakes made by programmers Neglecting to initialize the loop control variable Neglecting to alter the loop control variable Using the wrong comparison with the loop control variable Including statements inside the loop that belong outside the loop Most computer languages support a for statement for loop used when the number of iterations is known Loops are used to accumulate totals in business reports and to reprompt users for valid data



Похожие презентации
Mypresentation.ru
Загрузить презентацию