Crypto Mini-Lesson: Ethereum Virtual Machine (EVM)
Every EVM opcode has a fixed Gas cost. Operations like writing to storage are much more expensive than ordinary computation.
EVM execution must be deterministic: the same input must produce the same result on every node, or the nodes won't be able to reach consensus.
Back then, not understanding this cost me enough money to enjoy several hot pot meals.
When calling a contract on Ethereum, the EVM charges Gas for each instruction it executes, paid using $ETH . Current: 1829.74.

I'm just rambling—don't take this as advice.