Skip to main content
Logo image

PreTeXt Sample Book Abstract Algebra (SAMPLE ONLY)

Section 5.3 Code Lens

CodeLens is an interactive tool for following program execution, much like a debugger, without the ability to influence flow control or variable values. For use without a server, traces must be computed beforehand. First, we have some trivial programs, to provide minimal testing.
Listing 5.3.1. A Python program, stepable with CodeLens
Listing 5.3.2. An C program, stepable with CodeLens
Listing 5.3.3. A Java program, stepable with CodeLens
Codelens interactives can be given one or more checkpoints where the user is asked a question as the code is executed:
Listing 5.3.4. A Python program, stepable with CodeLens, with questions
If a Codelens contains checkpoints, it is also possible to make it into an exercise. For use on Runestone, there should be an @label on the exercise:

Checkpoint 5.3.5. A C++ program as CodeLens exercise.

Run the codelens and answer the questions it asks.
Now some moderately more complicated programs to find the prime numbers less than \(20\text{.}\) We do not vouch for the quality of these, or even their correctness!
Listing 5.3.6. Sieve of Eratosthenes, Java
Listing 5.3.7. Sieve of Eratosthenes, C++
Listing 5.3.8. Sieve of Eratosthenes, Java