Loops
Loops Three keys to making a loop work:
Loops Three keys to making a loop work: Getting it started right
Loops Three keys to making a loop work: Getting it started right Keeping it moving along
Loops Three keys to making a loop work: Getting it started right Keeping it moving along Determining when to quit looping
Loops Three keys to making a loop work: Getting it started right – initialization Keeping it moving along Determining when to quit looping
Loops Three keys to making a loop work: Getting it started right – initialization Keeping it moving along – iteration Determining when to quit looping
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
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
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
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
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
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
Testing Your Algorithm
Testing Your Algorithm Pretend you are the computer
Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step
Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping)
Testing Your Algorithm Pretend you are the computer “Execute” your algorithm step-by-step (single-stepping) Make no assumptions
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
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)
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
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?
Clear and Unclear Windows