In your case, you definitely should not.
Here is an example of what you want:
y = 5 + 4 - 2 + 7 - 4 - 5 + 1
…, then, to pop back to 5 when you are done.
You are doing that like this:
y = 5 push + 4 push - 2 push + 7 push - 4 push - 5 push + 1 pop pop pop pop pop pop
= 5
…but you could just do this:
y = 5 push + 4 - 2 + 7 - 4 - 5 + 1 pop
= 5
pushMatrix();
for (int i = 0; i < N; ++i) {
translate(0, 15);
rect(0, 0, 5, 5);
}
popMatrix();
Push isn’t for every transformation you make. It saves every place in a transformation stream that you want to back out to and re-branch from. You could make 100 story skyscrapers with thousands of complex components per story, and you might only need to push 3 levels deep–(building(floor(window))). The solar system has lots of objects with nested relative rotations, but you don’t push a new level for each object – any satellite of a moon of a moon of a planet around the sun is still only a few levels deep.
sun
push
Earth
push
moon
push
moonsat1
pop
push
moonsat2
pop
pop
push
spacestation
pop
pop
push
Venus
pop
So, if there is a wart on a frog on a bump on a log in a hole in the bottom of the sea, you only need to push seven deep – even if there are seven seas, dozens of holes, hundreds of logs … a thousands frogs, and millions of warts. Growing random branches on the logs and pushing 4000 relative frog legs still only takes you to 9 deep.
The matrix stack is also relatively expensive way of tracking transforms if you aren’t doing rotation or scaling–it is heavy duty and general purpose. If you really need to walk and unwind translate statements nested 300 deep–like some kind of relative fractal–consider something like an ArrayDeque<PVector>
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html