View Single Post
07-01-13, 01:56 AM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,334
Originally Posted by Clamsoda View Post
Edit: I am not sure how to break out of nested loops in Lua, the code may be able to be optimized a bit if someone sheds some light on that aspect.
What you'd have to end up doing is set a variable in the inner loop for a conditional in the outer loop to check for and break out if needed. The following example has the dual purpose of getting the position and breaking out of both loops when it's found.

Lua Code:
  1. --  Example of an item link
  2. local _,link=GetItemInfo(6948);
  3.  
  4. local bag,slot;--   These are nil to start with
  5. for i=0,NUM_BAG_SLOTS do
  6.     for j=1,GetContainerNumSlots(i) do
  7.         if GetContainerItemLink(i,j)==link then
  8.             bag,slot=i,j;-- Set vars
  9.             break;--    Breaks out of inner loop
  10.         end
  11.     end
  12.  
  13. --  Break out of outer loop if vars have been set by inner loop
  14.     if bag and slot then break; end
  15. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote