Change global state in list

public enum MyState
{
A,B,C
}

public class ABC
{
int length;
}

public List<ABC> abcs = new List<ABC>();
        
public MyState state = MyState.A;

void Start()
{
for(int i = 0 i < 5;i++)
{
ABC temp = new ABC();
tmp.length = 1 + i;
abcs.add(temp);
}
}

void Update(){  
foreach(ABC a in abcs)
{
if(a.length == 1)
state = MyState.B;
}
}

I want to change my custom enum when one is satisfy my condition in collection.
But only last one in collection will do , how to solve it ?

Thanks in advance.

You have to do

foreach(ABC a in abcs)
{
    if(a.length == 1)
    {
        state = MyState.B;
        break; // this causes foreach loop to stop and not check other ABC elements 'length' field
    }
}

You could also use LINQ for this (requires using System.Linq;) and just write

if(abcs.Any(a => a.length == 1))
{
    state = MyState.B;
}