What are good, practical labs and activities for unnested loops?
Note that the following are intended for the instructor, not always directly for the student. If used well they require some analysis, not just coding, from the student.
Use the fact that the sum of the first n odd numbers is $n^2$ to compute the integer square root of an integer.
Test data should include 63, 64, and 65 to catch edge cases.
This can be extended past the decimal point and optimized in various ways to compute more accurate approximations of square roots.

Notes on the above, but I suggest you try it before peeking:

To make it a bit more obvious, this involves using inverse functions and computing inverses. The loop actually needs to count subtractions and uses facts about perfect squares to compute square roots. That same idea might be exploited for other problems.

Note that $\lfloor$  $\sqrt 65$ $\rfloor$ = 8.


Other simple things:

How many digits does an integer have?

How many bits are required to represent an integer? (Note that the structure is the same as the above)

How many times does zero (for example) appear in the decimal representation of an integer.

Sum of the digits of a given integer.

Is the number of 1 bits in a binary representation of an integer even or odd?

Read a real value x from input. Then read the successive coefficients of a polynomial from input and evaluate the polynomial at x. Note that the stopping condition needs to be specified and by varying it you can have different systems. Reading it from input is one of the obvious variations. Hardcoding it is another. Later on, the coefficients can be in an array, of course.

In teaching loops it is important to also give exercises where the correct number of iterations is zero. For example, give x and y, find the number of multiples of 3 that are larger than x but less than y. Don't exclude the initial condition y &lt; x.

Nested loops: Once you have the solution to &quot;is X prime?&quot;, how many primes are there between a given x and y?



A bit harder:
Euclid's algorithm.

Extensions:

Use other similar sums (than the sum of odds) to compute other things.

Look at the Wikipedia article on Taylor Series to get some ideas about how to approximate some interesting functions with sums.



A solution to the square root problem follows, using a personal (executable) pseudocode:

     $ &quot;Computes the integer square root of a non-negative number&quot;;
    With
      value; current; count; odd; // integer variables
    Program
      Read value;
      current &lt;- value;
      count &lt;- 0;
      odd &lt;- 1;

      While current &gt;= odd {
          current &lt;- current - odd;
          odd &lt;- odd + 2;
          count &lt;- count + 1;
      }

      Print &quot;The integer square root of &quot;, value, &quot; is &quot;, count;
    End