Trying to Stop or Pause a for loop

Ok. So I have my code here below and my goal is to have the loop stop during the Players turn and then continue counting after the playerTurn(); function has been set back to false… is this even possible? I have tried many things out in order to make it work just wanted an extra set of eyes to help! Thanks.

function battle(){
	battleOrder();
	for(var i = 1; i <= 6; i++){
		if(win() == false && lose() == false){
			if(playerInitiative == i){
					print("Player Turn");
					playerTurn();
			}
			if(enemy1Initiative == i){
				print("Enemy1 Turn");
				enemyTurn(enemy1);
				//yield WaitForSeconds(1);
			}
			if(enemy2){
				if(enemy2Initiative == i){
					print("Enemy2 Turn");
					enemyTurn(enemy2);
					//yield WaitForSeconds(1);
				}
			}
			if(enemy3){
				if(enemy3Initiative == i){
					print("Enemy3 Turn");
					enemyTurn(enemy3);
					//yield WaitForSeconds(1);
				}
			}
			if(enemy4){
				if(enemy4Initiative == i){
					print("Enemy4 Turn");
					enemyTurn(enemy4);
					//yield WaitForSeconds(1);
				}
			}
		}
			if(i >= 5){
				i = 1;
			}
			yield WaitForSeconds(1);
			
		if(win() == true){
			winner = true;
		}
		else if(lose() == true){
			loser = true;
		}
		}
		
	}

You can stop a for loop (i.e. breaking out of it and continue executing the subsequent code) with the keyword break; … at least that is how it works in C#.

To pause a loop you could do something like this (not tested, but it should work):

int i;
int startingPoint;



 void Start()
 {
     startingPoint = 0;
 }


IEnumerator Calculate() // presumably called as a Coroutine
{
    loopIsRunning = true;
    for (i = startingPoint; i <= 6 && loopIsRunning; i++)
    {
        // CODE: calculations to be done

        // pause functionality
        while (!loopIsRunning)
        {
            yield return new WaitForSeconds(0.01f);
        }

        // done at the last iteration, so that next time, the loop starts from 0
        if (i == 6)
        {
            startingPoint = 0;
            loopIsRunning = false;
        }
    }
}

void PauseLoop()
{
     startingPoint = i;
     loopIsRunning = false;
}

void ContinueLoop()
{
     loopIsRunning = true;
}

Hope this helps.

Cheers

Bilo