Spanning Tree Protocol (STP) is a control plane mechanism for Ethernet. It is used to create a Layer 2 topology (a tree) by placing the root switch on top of the tree.
Since classical Ethernet works based on data plane learning and Ethernet frames don’t have TTL for loop prevention, loops are prevented by the STP blocking the links.
As you can see from the below figure, some links are blocked by the spanning tree. If Spanning Tree wouldn’t block those links, loop would occur in the below topology.