The name "i" does not exist in current context issue

I’m just getting started in C# and I’m unable to get this code to work. Am I doing something wrong?

using UnityEngine;

public class BlockSpawner : MonoBehaviour
{

    public Transform[] spawnPoints;

    public GameObject blockPrefab;

    public float timeBetweenWaves = 1f;

    private float timeToSpawn = 2f;

    void Update()
    {

        if (Time.time >= timeToSpawn)
        {
            SpawnBlocks();
            timeToSpawn = Time.time + timeBetweenWaves;
        }

    }

    void SpawnBlocks()
    {
        int randomIndex = Random.Range(0, spawnPoints.Length);

        for (int i = 0; i < spawnPoints.Length; i++)
        {
            if (randomIndex != i)
            {
                Instantiate(blockPrefab, spawnPoints[i].position, Quaternion.identity);
            }
        }
    }
}

No errors in that script. Are you sure you posted the right one?

If you got error, select them, tell us which line is it or comment this line. However I don’t see any error in this code.

In replying to the thread headline - I wonder, did you maybe have a semi colon at the end of line 29 meaning that “i” went out of scope for the subsequent lines?

Presumably the expectation is that this creates an object at all bar one spawn points at each periodic interval. What actually happened instead to make you think it is not working?