And there are for loops- and if statements, and function declarations, etc. It's very c-like without dynamic memory allocation and executed in a highly parallel context.
Your shader is also not necessarily called every frame, you control this. It could be called multiple times per frame or only at certain times.
Fragment shaders (one type of shader) is called for each fragment of the rendered geometry - in 2D or in screen space this is just a quad so effectively a panel of pixels.
You get to know your own location with something like UV or a pixel coordinate if you pass it from a vertex shader, so that you can sample input textures as needed to build whatever it is you're building.
If you're not doing multiple render targets, your only responsibility is setting to the fragment color variable which will be the final color of that pixel for the output texture.
And that could in turn be the input to another shader etc.
I usually recommend https://thebookofshaders.com/
It's very sad this was never completed. It's so good.