Practice · Conditional Logic & Loops
Bubble Sort
Why this is here
Sort the numbers 1–9. Two are highlighted at a time: click "Swap" if the left one is greater than the right one, otherwise click "Next". This isn't a fixed sequence of clicks — the correct action depends on reading the two highlighted values each time, and a wrong call actually executes (a bad swap really swaps), so the loop has a real condition in it, not just a counter. The status line reads "KEEP SORTING" until the array is actually sorted, however many rounds that takes.
KEEP SORTING
Initial state.