Endless counters in foreach loop

Hey Guys:)
Can anyone plz tell me how i can avoid my counters “nbr”, “nbr2” and “nbr2” going into somekind of endless loop?? I just want the counters to go up by 1 foreach item added to my list.
Here is my code:

	private bool _DisplayInventoryWindow = true;
	private const int Inventory_Window_ID = 1;
	private Rect _InventoryWindowRect = new Rect(10f,10f,300,290f);
	private static int _InventoryRows =4;
	private static int _InventoryCollums = 3;
	private int _InventoryCheck = _InventoryRows * _InventoryCollums;
	private bool InvFull = false;
	private int nbr = -1, nbr2 = 0, nbr3 = 0;

	public List<GameObject> _LootItems = new List<GameObject> ();

	//Button Prop
	private float ButtonWidth = 40f;
	private float ButtonHeight = 40f;
	private float _offset = 1.1f;

void OnGUI()
		if(_DisplayInventoryWindow == true)
		_InventoryWindowRect = GUI.Window (Inventory_Window_ID, _InventoryWindowRect, InventoryWindow, "Inventory"); 


     void InventoryWindow (int id)
    				foreach (GameObject go in _LootItems) {
    								if (nbr == _InventoryCollums) {
    										nbr -= _InventoryCollums;
    								if (_LootItems.Count >= 0)
    										GUI.Button (new Rect (_offset * (nbr * ButtonWidth), 20 + _offset * (nbr2 * ButtonHeight), ButtonWidth, ButtonHeight), (nbr3).ToString ());
    								if(nbr3 == _InventoryCheck)
    								InvFull = true;
    			Debug.Log ("nbr:" + nbr);
    			Debug.Log ("nbr3:" + nbr2);
    			Debug.Log ("nbr2:" + nbr3);

Your question is confusing. This code will go through each item in _LootItems every single frame that _DisplayInventoryWindow is true.

You never reset nbr, nbr2, and nbr3 to a default value after you’re done counting them. This is the problem. You may think it’s endlessly looping because OnGUI is an endless loop. I’m thinking you probably only want InventoryWindow to count the nbrs once every time InventoryWindow is initially displayed.