Thumbnail

Infinite loops in PureBasic 5.73


Infinite loops can be a pain in programming, because in most of the cases they will definitely want to be avoided,

but in some cases, such as incremental games, they are neccessary, so I have investigated how to do it in PureBasic.

The trick is to create a loop that runs as long as a condition is true so we have to make sure that the condition never becomes false.

The following loop will create a floating point number variable called StartingBalance and initialize it with the value 0.00000000

Then the loop will always increment it by 0.00000001, because if we start at 0 and always add 0.00000001 it will never be negative.

Since you may also want to wait for a while until the loop does the next incremental step I have added a delay of 1000 milliseconds, too.

The result will be printed in the debug output inside the PureBasic IDE for fast testing if it works as expected.

; This infinite loop will increment StartingBalance by 0.00000001 every 1000 milliseconds

Define StartingBalance.f = 0.00000000
While StartingBalance.f > -1
StartingBalance = StartingBalance + 0.00000001
Debug "You have " + StartingBalance.f + " BTC."
Delay(1000)
Wend

How do you rate this article?

3


Cheetah Faith
Cheetah Faith

Crypto enthusiast, programming enthusiast, music lover and animal lover from Germany


Programming Tutorials
Programming Tutorials

I will share short and easy lessons, exercises and examples about programming languages here

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.