What is the smartest/smarter way write repeating code? How to find/learn it?

I am new to unity and C#. Trying to make mini games little by little. Until now I’ve generally used a “pragmatic” but not very logical ways to code. They work which is great but…

I want to improve myself.

I don’t know how can I search for it. What is it called?

Right now my codes are like this…



 if (Mathf.Abs(pictures[0].rotation.z) < 0.05 &&
            Mathf.Abs(pictures[1].rotation.z) < 0.05 &&
            Mathf.Abs(pictures[2].rotation.z) < 0.05 &&
            Mathf.Abs(pictures[3].rotation.z) < 0.05 &&
            Mathf.Abs(pictures[4].rotation.z) < 0.05 &&
            Mathf.Abs(pictures[5].rotation.z) < 0.05 )

I change them if I can find a better way to code but can not understand the logic behind it. I just try different things until one of them works but could not change these ones. So I would be very happy if someone tells me how to search for it, or how can I make these codes better and shorter.

Thank you for reading.

In this case you would probably use a for loop: [for (C# reference)][1]

For example like this:

for (int i = 0; i < 6; i++) {

[1]: Iteration statements -for, foreach, do, and while | Microsoft Learn