|
Look at the statements inside of the loop body. Are there any that do exactly the same thing for each iteration of the loop? A good answer might be:Yes, these two statements:
keep computing the same thing over and over.
| |
Moving Statements Outside the LoopThere is no need to compute radius for each iteration of the loop. It will be "15" each time. The same for Y, the top edge of the squares. It is always the same. These two statments can be moved outside of the loop, as in the following version of the applet, and it will do exactly the same thing. (Of course, you have to adjust the indenting.)
This version is somewhat better than the previous version because needless computations are avoided. If the loop iterated millions of times (not unusual in larger programs) moving some statements outside the loop might make the program run faster. | |
QUESTION 15:In the above program (or the previous) what is the effect of changing the statement
to
Click Here after you have answered the question
|