how can i write logic like this into a forloop? - C#