Question 7.1

  1. a) Sequence, selection and repetition.
  2. b) if…else.
  3. c) Counter-controlled (or definite).
  4. d) Sentinel, signal, flag or dummy.

Question 7.2

  1. x = x + 1;
  2. x += 1;
  3. ++x;
  4. x++;

Question 7.3

  1. a) z = x++ + y;
  2. b) if ( count > 10 )document.writeln( "Count is greater than 10" );
  3. c) total -= --x;
  4. d) q %= divisor;
  5. q = q % divisor;

Question 7.4

Question 7.5

Equation here!

Question 7.6

7.6 Determine the value of each variable after the calculation is performed. Assume that, when each statement begins executing, all variables have the integer value 5.

  1. a) product *= x++;
  2. b) quotient /= ++x;

Question 7.7

7.7 Identify and correct the errors in each of the following segments of code:

  1. a) Error: Missing the closing right brace of the while body. Correction: Add closing right brace after the statement ++c;.
  2. b) Error: The ; after else causes a logic error. The second output statement always executes. Correction: Remove the semicolon after else.

Question 7.8

The value of the variable z is never changed in the body of the while statement. Therefore, if the loop-continuation condition (z >= 0) is true, an infinite loop is created. To prevent the creation of the infinite loop, z must be decremented so that it eventually becomes less than 0.