OSShakespeare.007: Shakespeare Programming — Counter-Controlled Loops and Countdown Termination

Theatrical scene with a countdown from four to one, followed by an exit at zero, BitcoinVersus.tech watermark.

Open-Source Shakespeare Programming • OSShakespeare.007 • 30–40 minutes

A scene jump can do more than choose between two outcomes. When a program jumps backward, it can repeat instructions until a stored integer reaches a termination condition. Shakespeare Programming Language (SPL) expresses this control flow as dialogue and stage directions rather than conventional loop keywords. The following exercise uses a fixed countdown to illustrate initialization, a condition, a state update and termination.

Prerequisites and objectives

Review arithmetic, questions and jumps and numeric output. Learners will identify a loop invariant, trace a countdown, distinguish the speaker from the addressee, and recognize why a condition must be checked before printing when the initial count can be zero.

Esoteric Programming Languages: Challenging the Norm. A broader introduction to unconventional languages, including Shakespeare; use the language specification for the exact countdown syntax. Original source.

How a countdown works

The original SPL specification describes positive and negative nouns, adjectives that double integer magnitude, comparisons, conditional statements and scene jumps. Romeo is initialized to zero and Juliet to four: the positive noun flower has value one, and two adjectives double it twice. With both characters on stage, Romeo can compare his zero value with Juliet’s current counter. If equal, the program jumps to the ending scene. Otherwise Romeo instructs Juliet to print her number, subtract one and repeat.

Interior of Shakespeare's Globe theatre with stage and galleries
John H Darch, May 19, 2016. Inside the Globe Theatre, CC BY-SA 2.0. Historical theatrical context, not an SPL runtime.

Original SPL exercise

The Last Four Bells.

Romeo, a keeper of silence.
Juliet, a keeper of numbers.

Act I: The Countdown.
Scene I: The Preparation.
[Enter Romeo and Juliet]

Juliet:
 You are nothing!

Romeo:
 You are a big big flower!

Scene II: The Counting.
Romeo:
 Am I as good as you?
 If so, let us proceed to scene III.
 Open your heart!
 You are as good as the difference between yourself and a flower.
 Let us proceed to scene II.

Scene III: The End.
[Exeunt]

Expected numeric output: 4321 with no separators. Scene I initializes values once; Scene II repeats while Juliet’s positive counter is nonzero. Scene III exits the characters. Do not jump back to Scene I: that would reset the counter on every iteration.

Executable reference model and verification boundary

def countdown(n):
    out = []
    while n > 0:
        out.append(n)
        n -= 1
    return out

assert countdown(4) == [4,3,2,1]
assert countdown(0) == []
assert countdown(1) == [1]
print('3 countdown model cases passed')

All three Python 3.13.5 reference-model cases passed: initial values four, zero and one. The model validates the intended countdown semantics, not the SPL parser. A native SPL interpreter was unavailable; the SPL example was reviewed against the specification but not executed. Use a compatible implementation such as shakespearelang 1.0 to verify the exact output. The example assumes a nonnegative integer; a negative input would require a different guard.

December 2023 Advent of Code community discussion includes a programmer describing writing an SPL solution directly. This illustrates practical experimentation with esoteric languages, not a language specification. Original source.

Debugging and exercises

If the program repeats indefinitely, inspect the initialization, the comparison and the decrement. Stage addressing must be valid; a scene jump does not itself move characters on or off stage. 1. What happens if Juliet starts at zero? The ending scene is reached before printing. 2. Why not jump back to Scene I? It resets the counter. 3. What is the intended output for a start of two? 21. 4. Why is the native test still necessary? Parser and runtime behavior may differ from the reference model. Review stacks and recall to distinguish loop state from temporary stack storage.

Editor’s Note: We volunteer daily to ensure the credibility of the information on this platform is Verifiably True.

BitcoinVersus.Tech publishes technology and financial journalism for informational purposes and does not provide financial, investment, or legal advice.

Leave a Reply