As a reminder, we can use for loops to repeat a block of code a fixed number of times.

When we need to repeat a block of code as long as a condition remains true, that’s a job for a while loop.

Operators allow us to assign values to a variable or a constant, perform arithmetic, or make comparisons.

NOTE

Remember that with integers, the / operator provides the quotient of a division operation, and the % operator provides the remainder of a division operation.

For example, the expression 14 / 3 provides 4 and the expression 14 % 3 provides 2, since three goes into fourteen four times, leaving a remainder of two.

Conditional statements allow us to selectively run blocks of code when given a condition is true. If needed, we can check multiple conditions.

If we need to check many conditions and run different code for each condition, a switch statement might be easier to use.

Exercise

RSA Numbers

Try the following puzzle involving identifying RSA numbers.

Note that after collecting input for this puzzle, in the processing section, the solution involves combining both loops and conditionals.

Please work with a partner using the driver-navigator pattern to complete this exercise.

Begin by making a new macOS command line project named RSANumbers:

You can test the correctness of your solution using this test plan.