I need my script to continue after i have set the first, help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// bla bla bla
from line 33

		foreach (var b in buttonlist) {
			Inactivebuttonlist.Add (b);

			buttonlist.Remove (b);

			b.gameObject.SetActive (false);

			**// My function stop here, but there is still more to be done**

		}

		PlanetAdminHolder.SetActive (false);

		// bla bla bla

when you are removing the item from the list it is changing the length (count) of the list, maybe it has something to do with that.

try something like:

foreach (var b in buttonlist) {
             Inactivebuttonlist.Add (b);
             b.gameObject.SetActive (false);
         }
         buttonlist.clear(); //empty the list after the foreach has run its course
         PlanetAdminHolder.SetActive (false);
         // bla bla bla