|
What is the more frequently performed operation in an executing program? A good answer might be:The most frequently performed operation is adding one to a variable. |
Adding OneMost programs have many loops in them and most loops are controlled by a variable which counts the number of times the loop has executed. Of course, each time the loop executes, ONE is added to the variable. Also, there are many other situations where one is added to a variable. Computer engineers have observed many executing programs and have found that adding one to a variable is the most frequently executed operation. All processor chips have been designed to make this operation very, very fast. You already know how to add one to a variable: This is easy enough, but since it is so common it would be nice to have a brief way of doing it. Here is one way:counter = counter + 1 ; // add one to counter The above statement uses the increment operator ++ to add one to the value in counter. It has the same effect as the first statement. Here is a counting loop:counter++ ; // add one to counter
|
QUESTION 2:Fill in the blank so that the loop prints 0 through 9. Use the increment operator. Click Here after you have answered the question |