The Logic League
Loop Inside a Loop

The Woven Garden
The laptop glowed softly in the lost-and-found closet, its screen rippling like water in a breeze. Priya touched the glass, and the familiar green text poured down.
WELCOME, LOGIC LEAGUE.
REGION: DATA DEPTHS, LEVEL 3.
CAUTION: RECURSION DETECTED AHEAD.
"Recursion?" Kwame raised an eyebrow. "That was Book 21. We did the staircase that contains a staircase. What's next?"
The screen flickered and showed a single word: WEAVE.
Then the world tilted, and they were falling.
They landed—softly, this time—in what appeared to be an enormous garden. But it was a garden like nothing they'd ever seen. The paths did not run straight. They curled in spirals, looping back on themselves, weaving around beds of flowers that grew in repeating patterns. The whole place hummed with a quiet, rhythmic pulse, like a heartbeat made of geometry.
"Look at the flowers," Lily said, already crouching close. "They're in rows. But the rows... the rows are rows of rows."
Sam squinted. "What does that mean?"
Kwame followed Lily's pointing finger. The flowers grew in neat lines, but the lines themselves were arranged in bigger lines—a pattern of patterns. It was like looking at a woven cloth where each thread was itself a tiny braid.
"I think this place is made of loops," Kwame said slowly. "Little loops inside big loops. Like a song that repeats a verse, and the verse repeats its own smaller melody."
Priya was pacing, counting under her breath. "One, two, three, four. Repeat. One, two, three, four. Repeat. But look—after every four rows, there's a gap, and then the whole block of four rows starts again." She stopped, pointing at the garden's layout. "The blocks are loops. Inside each block, the rows are loops. Loops inside loops."
Sam tilted their head. "Why would anything need a loop inside a loop? Couldn't you just make one really long loop for all the flowers?"
The garden seemed to hold its breath.
Lily was already at the edge of the nearest bed, studying a small wooden sign. "I think this is a puzzle," she said. "The sign says: PLANTING SEQUENCE REQUIRED. COMPLETE THE WEAVE. "
The kids gathered around. The sign had a grid carved into it—a pattern of empty slots, each one shaped like a flower. And beside the grid, words:
FOR EACH ROW:
FOR EACH FLOWER IN ROW:
PLANT SEED.
"That's it?" Priya frowned. "That's the whole instruction?"
ERROR: SEQUENCE INCOMPLETE.
OUTER LOOP DETECTED. INNER LOOP DETECTED.
BUT NO STOPPING CONDITION GIVEN FOR EITHER.
Kwame read the error message out loud, frowning. "So we know we need to plant in rows, and each row needs flowers in it. But the loops don't say when to stop."
"Of course they don't," Lily said, pulling out her magnifying glass. "A loop without an exit condition is just... infinite. It would plant seeds forever."
As she spoke, the garden began to tremble. At the far end of the nearest flower bed, a small mechanical gardener—a clunky, cheerful-looking robot with a watering can for a head—started moving. It trundled along the first row, dropping seeds into the prepared soil. It reached the end of the row... and turned around, dropping more seeds on top of the ones it had already planted.
"This is bad," Priya said. "It's going to keep planting forever. The garden will be buried in seeds."
The robot reached the end of the first row and moved to the second row—but it didn't continue down the row. It simply planted in the first slot of the second row, then doubled back to replant the first row again.
"Wait, that's weird," Sam said. "Why is it planting out of order?"
Lily watched closely, her brow furrowed. "Because the inner loop is stuck," she said. "The instruction says: for each flower in row, plant seed. But it doesn't say to move to the next flower. It doesn't have an exit condition. So it keeps planting the same flower over and over."
The robot was now frantically dropping seed after seed into a single slot, creating a small mountain of seeds that threatened to overflow.
"It needs to know when it's done with one loop and should move to the next," Priya said, pacing. "But how do we tell it?"
Sam's Question
"Maybe the problem isn't the loops," Sam said quietly.
Everyone turned. Sam was sitting cross-legged on the garden path, watching the robot's frantic planting with a curious expression.
"What do you mean?" Kwame asked.
"Look at the sign again," Sam said, pointing. "It says: for each row, for each flower in row, plant seed. But it doesn't say what to do after. It's just... the same instruction, forever, at every level."
Lily's eyes widened. "Sam's right. The sign tells the robot WHAT to do for each flower and WHAT to do for each row, but it never says what happens when the flower is planted or when the row is done. The loops don't just need stopping conditions—they need clear instructions about what happens INSIDE each iteration."
Priya stopped pacing. "So the fix is..."
"To tell the robot what to do at the end of each flower and at the end of each row," Kwame finished. "The inner loop needs to know: plant seed, then move to the next slot. And the outer loop needs to know: after all the flowers in a row are planted, move to the next row."
Lily pulled out her notebook—she always carried it in the Grid, for debugging notes—and sketched quickly:
FOR EACH ROW:
FOR EACH FLOWER IN ROW:
PLANT SEED.
MOVE TO NEXT SLOT.
MOVE TO NEXT ROW.
"See?" She showed the others. "The inner loop does its job for one flower, then moves to the next. When the row has no more flowers, the outer loop kicks in and moves to the next row. Each loop knows what it's doing and when it's done."
"But how do the loops know when a row has no more flowers?" Sam asked, squinting at the sketch. "What if there are different numbers of flowers in different rows?"
The garden pulsed again. The robot stopped mid-planting, frozen in place.
"That's a good question," Priya said slowly. "How WOULD the robot know?"
Kwame looked at the garden layout, counting the flower beds. "Maybe the Garden is organized in blocks," he said. "Uniform blocks. Each block has the same number of rows. Each row has the same number of flowers. The loops can count because the pattern is regular."
"Like a grid," Lily said, nodding. "A consistent structure. Once you know the size of the block and the size of each row, the loops can run a fixed number of times."
She amended her sketch:
FOR EACH OF 6 ROWS:
FOR EACH OF 8 FLOWERS IN ROW:
PLANT SEED.
MOVE TO NEXT SLOT.
MOVE TO NEXT ROW.
"Six rows, eight flowers each," she said. "The outer loop runs six times. Each time it runs, the inner loop runs eight times. Every flower gets planted exactly once."
"Six times eight," Sam said, their voice brightening. "That's forty-eight flowers."
"Exactly," Priya said. "The inner loop happens forty-eight times total—eight for each of the six rows. But the outer loop only runs six times. The loops are nested, so the inner one repeats for every single item the outer one touches."
The garden was waiting. The instruction needed to be given—in the Grid, you didn't just think about solutions; you had to make them real.
Kwame reached toward the wooden sign. "We have to update the instruction." He touched the carved words, one by one, tracing them with his finger.
As he did, glowing letters appeared beneath the original text, filling in the missing pieces:
FOR EACH OF 6 ROWS:
FOR EACH OF 8 FLOWERS IN ROW:
PLANT SEED.
AFTER EACH FLOWER: MOVE TO NEXT SLOT.
AFTER EACH ROW: MOVE TO NEXT ROW.
The sign shimmered, and the garden began to hum.
The Weave Completes
The robot's watering-can head swiveled with a cheerful click. It raised its little trowel arm and trundled to the first row.
"Watch," Priya whispered.
The robot planted a seed in the first slot. Then it moved to the next slot. Plant, move. Plant, move. Eight seeds in a row, perfectly spaced. When it reached the end of the first row, it turned—and moved to the second row. Plant, move. Plant, move.
"Now look at the rows," Lily said, pointing at the garden.
As the robot worked, the rows began to connect. Vines crept from one planted seed to the next, weaving through the soil. The pattern was becoming visible: each row was a golden thread of light, and the rows were weaving together into a broader design.
"Loops inside loops," Kwame murmured. "The inner loop makes the tiny pattern of one row. The outer loop repeats that pattern across all the rows. Together they make the whole weave."
"The whole is just the little thing, repeated," Sam said. "But with more repeat."
"Exactly," Priya said. "A loop inside a loop. Each time the outer loop runs, the inner loop runs all the way through. The inner loop is inside the outer loop."
The robot finished the last row and made a cheerful ding. The garden was aglow—golden rows of light interwoven at perfect right angles, like a quilt sewn from sunlight.
The sign changed.
WEAVE COMPLETE.
NESTED LOOPS: A LOOP RUNNING INSIDE ANOTHER LOOP.
FOR EVERY ITEM IN THE OUTER LOOP, THE INNER LOOP RUNS FOR ALL ITS ITEMS.
The garden spread out before them, no longer chaotic but serene. The repeating patterns were beautiful now, each flower in its place, each row woven into the next.
Sam hopped along the path, counting under their breath. "Six rows, eight flowers in each row. The robot did forty-eight plants because it did eight, six times."
"Or six, eight times," Lily said, catching up. "Depends on which loop you're thinking about."
"That's the tricky part," Kwame said, pulling out his journal. He sat on a bench near the garden's edge and began to write.
KWAME'S JOURNAL — ENTRY 22
The garden taught me something today about how big things are made. A song isn't one long melody—it's a verse that repeats. And inside that verse, there's a smaller pattern that repeats too. The verse is the outer loop, and the smaller pattern is the inner loop. The inner loop completes every time before the outer loop moves on. You don't get to the second verse until you've finished the entire first verse, including all its smaller patterns.
When I think about it, a story is nested loops too. Each chapter has moments that repeat—the hero faces a challenge, learns something, changes. Then the chapter ends, and the next chapter begins, and the moments repeat again. But each time the outer loop runs, the inner loop is slightly different because the characters have learned something.
The tricky part of nested loops is remembering which loop you're inside. When I'm in the inner loop, I need to focus on the small pattern. When the inner loop finishes, I step back into the outer loop and remember the bigger pattern. The sign in the garden said: FOR EACH ROW, FOR EACH FLOWER. If I lost track, I might try to plant all forty-eight seeds in one row, or plant the same seed twice. Track the loops. Know which level you're on.
The garden made me think of my grandmother's quilt. She stitches each square completely—every tiny pattern—before moving to the next square. Then she joins the squares into rows, and the rows into the whole quilt. Every square is an inner loop. Every row is an outer loop. And the quilt? The quilt is what happens when you multiply.
Loops inside loops. Small patterns building big patterns. I like that.
The Return
The garden shimmered, the golden light folding in on itself, and the kids felt the familiar pull of the transition. The Data Depths faded, the gardening robot waved its trowel as it began planting a second block—its same six-by-eight weave, now running as the inner loop inside some larger pattern the kids couldn't see.
Then the world snapped back, and they were in the lost-and-found closet, the laptop's screen going dark.
Priya let out a breath. "Nested loops," she said. "I kept thinking of them as two separate things, but they're just... one thing inside another. The inner loop is the detail. The outer loop is the big picture."
"Each one runs its course," Kwame said, tucking his journal into his backpack. "The inner loop finishes every iteration before the outer loop moves on. That's what keeps the pattern clean."
Lily was already rewriting her notes. "The error message was ELITE, though: 'NO STOPPING CONDITION DETECTED FOR EITHER.' It wasn't wrong. It was just... unhelpful."
"And it made us figure out the answer ourselves," Sam said, grinning. "That's kind of how it works. The Grid tells you what's wrong, but you have to know how to fix it."
Mr. Kofi appeared in the doorway, a stack of books in his arms. "Ah, there you are. I thought I heard voices." He smiled, glancing at the laptop, then away. "Did you find what you were looking for?"
"Not exactly," Priya said. "We found a garden. And a robot. And a pattern."
Kwame smiled. "We found the pattern."
Mr. Kofi nodded, as if that made perfect sense. "Patterns," he said. "The world is full of them. The trick is knowing which level you're looking at."
He reached into his stack of books and pulled out one with a woven cloth on the cover—a pattern of threads, each thread itself made of smaller threads. "This might interest you," he said. "It's about how small repeated patterns weave into larger ones."
Lily took the book, turning it over in her hands. "Thanks, Mr. Kofi."
He nodded and walked away, and the kids shared a look.
"He knows," Sam whispered. "He has to know."
"But he never says," Kwame said. "Maybe the knowing is part of the program."
Outside the closet's window, the afternoon sun slanted through the curtains, making a pattern on the floor—light and shadow, repeating in rows. The kids watched it for a moment, counting the rows, feeling the inner pattern of each stripe.
Then they stepped back into the world, carrying the weave with them.
Next time: Book 23 — Is It True? All of It? — When the Gate of AND requires every single condition to be true at once...