Loop Analysis
Tracing loops: 4.5.1
- Tracing tables are useful to keep track of variables
- Useful when loops have multiple
Counting loop iteration: 4.5.2
- Loops can be analyzed to determine how many times they run
run-time analysis
- a
statement execution count
- A loop will execute
(largestValue - smallestValue) + 1
times- if a loop uses
counter <= limit
,limit
is the largest valuecounter < limit
,limit-1
is the largest value
- if a loop uses
Nested loop iterations
- A nested for loop body executes can be found with a standard formula
- outer loop iteration * inner loop iterations
Summary: 4.5.4
- A trace table can be used to keep track of variables and their values
- Useful when tracking loop iterations
- The number of times a segment will execute is determined with a
statement execution count
- This process is
run-time analysis
- This process is
- The number of times a loop executes is determined by
(largestValue - smallestValue) + 1
- The number of times a nested loop runs is determined by
- outer loop iterations * inner loop iterations
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
This was adapted from the CS Awesome curriculum, which was created by
Barbara Ericson, Beryl Hoffman, and many other CS Awesome contributors. All rights reserved.
CS Awesome is licensed under CC BY-NC-SA 4.0.