Download presentation
Presentation is loading. Please wait.
1
Loops
2
Loops Three keys to making a loop work:
3
Loops Three keys to making a loop work: Getting it started right
4
Loops Three keys to making a loop work: Getting it started right
Keeping it moving along
5
Loops Three keys to making a loop work: Getting it started right
Keeping it moving along Determining when to quit looping
6
Loops Three keys to making a loop work:
Getting it started right – initialization Keeping it moving along Determining when to quit looping
7
Loops Three keys to making a loop work:
Getting it started right – initialization Keeping it moving along – iteration Determining when to quit looping
8
Loops Three keys to making a loop work:
Getting it started right – initialization Keeping it moving along – iteration Determining when to quit looping – exit conditions
9
Get smallest # (smallest # algo) New list starts w/2nd item
Start w/full list Remember start of list Get smallest # (smallest # algo) Swap w/1st New list starts w/2nd item New list have #? No Yes Orig list is sorted
10
Get smallest # (smallest # algo) New list starts w/2nd item
Start w/full list Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item New list have #? No Yes Orig list is sorted
11
Get smallest # (smallest # algo) New list starts w/2nd item
Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item New list have #? No Yes Orig list is sorted
12
Get smallest # (smallest # algo) New list starts w/2nd item
Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item Iteration get to next loop New list have #? No Yes Orig list is sorted
13
Get smallest # (smallest # algo) New list starts w/2nd item
Start w/full list Initialization Remember start of list Get smallest # (smallest # algo) Swap w/1st Loop New list starts w/2nd item Iteration get to next loop New list have #? No Exit condition Yes Orig list is sorted
14
Testing Your Algorithm
15
Testing Your Algorithm
Pretend you are the computer
16
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step
17
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping)
18
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions
19
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it
20
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list)
21
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list) Make sure you do this with boundary condition data
22
Testing Your Algorithm
Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions Try to do each step exactly as you wrote it Start with an easy set of data (i.e. your number list) Make sure you do this with boundary condition data Questions?
23
Clear and Unclear Windows
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.