# Ch 23: Jumping Back and Forth

> Study guide to Crafting Interpreters chapter 23. Control flow in bytecode: jump instructions with backpatching for if/else, logical operators, while loops…

Updated October 20, 2026.

## Summary {#summary}

Crafting Interpreters chapter 23, Jumping Back and Forth: Control flow in bytecode: jump instructions with backpatching for if/else, logical operators, while loops with backward jumps, and for loops. Budget about 5 hours; the book's `chap23_jumping` tests check your code.

## Key facts {#key-facts}

- Week 21 of 145 on the cracked.guide path, in [Crafting Interpreters](https://cracked.guide/crafting-interpreters).
- Time budget: about 5 hours.
- Part of the book: clox (bytecode VM, C).
- Verified on cracked.guide when the official `chap23_jumping` tests pass on GitHub Actions.
- 3 challenges at the end of the chapter.

## Week 21 goals {#objectives}

By the end of week 21 you can:

- Implement if, while and for with jump instructions.
- Explain how patchJump fills in a forward jump's offset after the body.
- Trace how `and` and `or` short-circuit using conditional jumps.

## This week's steps {#steps}

- Read the chapter: Disassemble each control structure and draw the jump arrows.
- Write the code in your lox repo: Type it into clox/ (C) yourself as you read, and get it running.
- Do the challenges (1–3): Challenge 1 (a switch statement) and challenge 2 (continue) are both excellent.
- Push and let the tests verify it: Your repo runs the book's chap23_jumping tests on every push; passing marks this done.

## Why it matters {#why}

Backpatching is how every assembler and compiler resolves forward jumps. You will see it again in real assemblers and in Knuth's MIX.

## How to approach it {#approach}

Disassemble each control structure and draw the jump arrows. Off-by-one jump offsets are the usual bug; the disassembler shows them immediately.

## Challenges {#challenges}

3 challenges at the end of the chapter.

Challenge 1 (a switch statement) and challenge 2 (continue) are both excellent. Challenge 3 is an open design question. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.

## Common traps {#traps}

- Jump offsets off by the size of the operand bytes.
- Not popping the condition value on both branches.

## Links {#links}

- [Read the chapter: Ch 23: Jumping Back and Forth](https://craftinginterpreters.com/jumping-back-and-forth.html)
- [Official repo: book source, both interpreters, test suite](https://github.com/munificent/craftinginterpreters)
- [Running the official test suite against your own interpreter (repo README)](https://github.com/munificent/craftinginterpreters#testing-your-implementation)

---

Source: https://cracked.guide/guide/ci-23
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
