# Break is broken?

**URL:** https://community.silverbullet.md/t/break-is-broken/3739
**Category:** Troubleshooting
**Created:** [January 8, 2026, 5:03am UTC](https://community.silverbullet.md/t/break-is-broken/3739 "2026-01-08T05:03:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![scanarr](https://community.silverbullet.md/user_avatar/community.silverbullet.md/scanarr/32/2779_2.png) [@scanarr](https://community.silverbullet.md/u/scanarr)
#### Post date: [January 8, 2026, 5:03am UTC](https://community.silverbullet.md/t/break-is-broken/3739/1 "2026-01-08T05:03:31Z")

</div>

I’ve recently started playing with SilverBullet and Lua and have found an oddity with looping that appears to be a bug; specifically, when breaking from a key, value loop, it sometimes causes an error.

Here’s a starting code block that works:

```lua
      ${(function()
        local fruits = {"apple", "banana", "cherry"}
        local result = {}
        for index, fruit in ipairs(fruits) do
          table.insert(result, fruit)
        end
        return result
      end)()}
      
      - apple
      - banana
      - cherry

```

Now add a break. Instead of returning just the first item, it returns an error:

```lua
      ${(function()
        local fruits = {"apple", "banana", "cherry"}
        local result = {}
        for index, fruit in ipairs(fruits) do
          table.insert(result, fruit)
          break -- leave with first fruit
        end
        return result
      end)()}
      
      Lua error:

```

Oddly, if you add more code, the error goes away:

```lua
      ${(function()
        local fruits = {"apple", "banana", "cherry"}
        local result = {}
        for index, fruit in ipairs(fruits) do
          table.insert(result, fruit)
          local foo = {} -- it doesn't seem to matter what else you do here
          break
        end
        return result
      end)()}
      
      - apple

```

Incremental loops don’t appear to have this problem:

```lua
      ${(function()
        local fruits = {"apple", "banana", "cherry"}
        local result = {}
        for i = 1, #fruits do -- switch to incremental loop
          table.insert(result, fruits[i])
          break
        end
        return result
      end)()}
      
      - apple

```

Is there some Lua convention that I’m missing here, or is this just a bug in SB or Lua?

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [January 8, 2026, 7:21am UTC](https://community.silverbullet.md/t/break-is-broken/3739/2 "2026-01-08T07:21:27Z")

</div>

You hit a bug in our Lua implementation, I just fixed it here: [Lua: fix `break` edge case · silverbulletmd/silverbullet@cb0c741 · GitHub](https://github.com/silverbulletmd/silverbullet/commit/cb0c74146d5b7934188c58d893e3127f125baf3f)

Thanks for reporting!
