Use for-i-loop var outside the loop

Hello, dear community. I am stuck with a trivial problem: using the value of a variable outside the loop.

Currently “i” seems to be accesible only inside the for-loop. I would like to use its value in the Update and other function.

Since I would like a variable to change every second. Is it possible?

My current script in c#:

using UnityEngine;
using System.Collections;

public class time2 : MonoBehaviour {
public int i;

	void Update () {
		StartCoroutine(Stopwatch());
		Debug.Log ("Now i is equal to:");
		Debug.Log (i);
		}

	IEnumerator Stopwatch(){
		for (int i = 0; i < 10; i++){
		yield return new WaitForSeconds(1);
		}
	}
}

using UnityEngine;
using System.Collections;

public class time2 : MonoBehaviour {
public int i;
 
    void Update () {
        StartCoroutine(Stopwatch());
        Debug.Log ("Now i is equal to:");
        Debug.Log (i);
        }
 
    IEnumerator Stopwatch(){
        for (i = 0; i < 10; i++){
        yield return new WaitForSeconds(1);
        }
    }
}

Removing the int declaration of the for loop it will use the class variable instead of its own local variable. This way you can see its value outside the loop.

using UnityEngine;
using System.Collections;

public class time2 : MonoBehaviour {
    public int i;
 
    void Update () {
        StartCoroutine(Stopwatch());
        }
 
    IEnumerator Stopwatch(){
        for (i = 10; i < 20; i++){
            yield return new WaitForSeconds(1);
            Debug.Log (i);

            }
    }
}