Let's talk about the Ethereum Virtual Machine (EVM).
Each EVM opcode has a corresponding Gas cost. Operations like writing to storage are much more expensive than ordinary computation.
One thing many people overlook: the EVM charges Gas for every instruction. Once a transaction runs out of Gas, it is halted and its state changes are reverted, so an infinite loop can't stall the entire network.
Before interacting with a contract, check on a block explorer whether its source code has been verified. Be extra cautious with contracts whose source code isn't public.
When calling a contract on Ethereum, the EVM charges Gas for each instruction it executes, paid in $ETH . The current price is 1701.5.