W
WP
Hello, I just tried a foreach loop with a Stack (Stack<String> to be
precise) and I was a bit surprised that it seems to iterate from the
bottom up. I thought it would go from the top down because, with
stacks, you usually have to remove what's on the top to get to the
bottom. Note that I didn't want to empty the stack itself, just
iterate over it. Why was it implemented this way? It's not an actual
problem, I simply adapted my logic in the method to this behavior,
but, as I said, I was surprised.
- WP
precise) and I was a bit surprised that it seems to iterate from the
bottom up. I thought it would go from the top down because, with
stacks, you usually have to remove what's on the top to get to the
bottom. Note that I didn't want to empty the stack itself, just
iterate over it. Why was it implemented this way? It's not an actual
problem, I simply adapted my logic in the method to this behavior,
but, as I said, I was surprised.
- WP