Why is unity exiting a loop inside a coroutine after its first run through?

Hello, I need help to figure out what is wrong with my code. I run this coroutine and give it a number of lines to loop through (more than one) (I have checked that this number isn’t 1), but the loop only runs once and stops at the end (possibly something to do with the WaitForSeconds command). Please tell me why it doesn’t continue with it’s loop and help me with a solution.

private IEnumerator If (List<string> ifLines) {
    		for (int i = 0; i < ifLines.Count; i++) {
    			int wait = 0;
    			string line = ifLines *;*
  •  	if (line.Contains ("opendoor")) {*
    
  •  		if (line.Length == 11) {*
    
  •  			char[] chrs = line.ToCharArray();*
    
  •  			if (chrs[8] == '(' && chrs[10] == ')') {*
    
  •  				string sChr = "" + chrs[9];*
    
  •  				int chr = 0;*
    
  •  				int.TryParse (sChr, out chr);*
    
  •  				if (chr > 0 && chr < 10) {*
    
  •  					Debug.Log ("Opened Door " + chr);*
    
  •  				}*
    
  •  			}*
    
  •  		}*
    
  •  	} else if (line.Contains ("closedoor")) {*
    
  •  		if (line.Length == 12) {*
    
  •  			char[] chrs = line.ToCharArray();*
    
  •  			if (chrs[9] == '(' && chrs[11] == ')') {*
    
  •  				string sChr = "" + chrs[10];*
    
  •  				int chr = 0;*
    
  •  				int.TryParse (sChr, out chr);*
    
  •  				if (chr > 0 && chr < 10) {*
    
  •  					Debug.Log ("Closed Door " + chr);*
    
  •  				}*
    
  •  			}*
    
  •  		}*
    
  •  	} else if (line.Contains ("lights")) {*
    
  •  		if (line.Length == 12) {*
    
  •  			char[] chrs = line.ToCharArray();*
    
  •  			if (chrs[6] == '(' && chrs[8] == ')' && chrs[9] == '.' && chrs[10] == 'o' && chrs[11] == 'n') {*
    
  •  				string sChr = "" + chrs[7];*
    
  •  				int chr = 0;*
    
  •  				int.TryParse (sChr, out chr);*
    
  •  				if (chr > 0 && chr < 10) {*
    
  •  					Debug.Log ("Light " + chr + " activated");*
    
  •  				}*
    
  •  			}*
    
  •  		} else if (line.Length == 13) {*
    
  •  			char[] chrs = line.ToCharArray();*
    
  •  			if (chrs[6] == '(' && chrs[8] == ')' && chrs[9] == '.' && chrs[10] == 'o' && chrs[11] == 'f' && chrs[12] == 'f') {*
    
  •  				string sChr = "" + chrs[7];*
    
  •  				int chr = 0;*
    
  •  				int.TryParse (sChr, out chr);*
    
  •  				if (chr > 0 && chr < 10) {*
    
  •  					Debug.Log ("Light " + chr + " deactivated");*
    
  •  				}*
    
  •  			}*
    
  •  		}*
    
  •  	} else if (line.Contains ("wait")) {*
    
  •  		if (line.Length == 7) {*
    
  •  			char[] chrs = line.ToCharArray();*
    
  •  			if (chrs[4] == '(' && chrs[6] == ')') {*
    
  •  				string sChr = "" + chrs[5];*
    
  •  				int chr = 0;*
    
  •  				int.TryParse (sChr, out chr);*
    
  •  				if (chr > 0 && chr < 10) {*
    
  •  					wait = chr;*
    
  •  				}*
    
  •  			}*
    
  •  		}*
    
  •  	}*
    
  •  	yield return new WaitForSeconds (wait);*
    
  •  }*
    
  •  //yield return null;*
    
  • }*

Problem solved. This issue was that I hadn’t realised that Lists reference to each other, so when I cleared the ifList, ifLines went blank aswell.