I know how this loop works, and how I can use it in practical problems. But I want to know what is happening under the hood.
I thought that this loop was similar to a regula
Every iteration of the loop creates a local variable x and initializes it to the next element of vec. When the loop iteration ends, x goes out of scope. A single x is never modified.