What Is An Infinite Loop?
An infinite loop is a sequence in a computer program looping continuously without stopping. Infinite loops are usually a bug and stop when a server is shut down to fix the bug, rewrite the code attached to the bug, and then redeploy the program.
This wouldn’t work on a decentralized and distributed blockchain network. It would be difficult to stop all the nodes around the world. Even if you were, with increasing transactions per second, this would cause thousands of transactions to build up. Even if it were for a minute.
Ethereum Gas And Infinite Loops
To stop this issue, Ethereum introduced Gas. Like a car that stops when it runs out of gas, if a transaction runs out of gas it’s stopped.
Before sending a transaction you set a gas limit you’d be willing to pay. If a transaction or smart contract gets stuck in a loop and runs out of ‘gas’ it reverts the computation and sends it back to you, without the gas you lost, unfortunately.
Gas also prevents spamming and DDoS attacks. Paying the gas fee for thousands of bots to flood a system would cost an attacker too much to be worth it. Making a blockchain system even more secure for its users.