title: How to break a for loop before it finishes going through all of its iterations Godot gdscript
body: <p>I am having an issue with my for loop in godot and hopefully you can help please!</p>
  <p>For my game inventory system, I am using a <code>for</code> loop to update the quantity of items in the inventory. For example, if I fire an arrow, the <code>for</code> loop will loop through all the inventory slots, find one with arrows and reduce the amount by one, as shown here:</p>
  <pre><code>    for slot in range(0, inventory_maxSlots):
          
          if (inventory[String(slot)][&quot;id&quot;] == String(item)):
              var newAmount = inventory[String(slot)][&quot;amount&quot;] - 1
              if (newAmount == 0):
                  inventory_updateItem(slot, 0, 0)
                  update_slot(slot)
              else:
                  inventory[str(slot)] = {&quot;id&quot;: str(item), &quot;amount&quot;: int(newAmount)}
                  update_slot(slot)
  
  </code></pre>
  <p>This works perfectly except for when I have stacks of arrows in more than one slot. If I have 3 slots filled with 10 arrows each, for example, after firing 1 arrow, all stacks will be reduced by 3. So I will end up with 3 stacks of 7 arrows. If I had 4 stacks of arrows, then each get reduced by 4 etc.</p>
  <p>I just want the loop to start, find the first slot with arrows, reduce its amount by 1 and then stop. I tried using a <code>Break</code> but it only seemed to stop the loop once it had run through all of the slots, and not just the first slot with arrows it finds.</p>
  <p>I am only a couple of months into learning programming so I have probably missed something really obvious and I would greatly appreciate any help!</p>
  <p>Thanks.</p>