# Running and stopping a program [Programming guides](README.md) Ordinary top-level setup statements execute in source order while top-level `when` statements register event scripts. After setup, the runtime runs the registered `started` scripts, arms every one-shot `after` script, and processes queued message work cooperatively. A program normally finishes when neither ready nor sleeping scripts remain, unless persistent key or pointer handlers keep it waiting for input. `exitApp()` finishes the complete program immediately and successfully, even from a nested function, loop, or event script. Remaining work does not run. In an [IDE](../concepts/ide.md) or browser preview, `exitApp()` finishes only the learner program's execution session and leaves the preview available for inspection. A native graphical program that naturally reaches its final statement retains its last frame until the user closes the window; `exitApp()` instead requests normal host shutdown and resource cleanup. `return` exits only the current function. IDE Stop is external cooperative cancellation and is not Pliro syntax. Positive `wait` calls and completed input requests are cooperative checkpoints. They keep Stop and graphical event processing responsive and start a fresh instruction-budget slice. In an event script, `wait` parks only the active script. `broadcast` queues exactly matching message scripts and yields the active script so the deterministic [FIFO](../concepts/event-loop.md) scheduler can continue other ready work. Put a persistent animation loop in `when started():` when other event handlers need to run during its waits; ordinary top-level setup must finish before the event-scheduler phase begins. ```pliro # language: en let running = true while running: if keyDown("space"): exitApp() # Update and draw one frame here. wait(0.04) ``` ## Related entries [Syntax and values](../syntax/README.md) · [Built-ins](../builtins/README.md) · [Programming guides](README.md)