read.cash Log in
C@Cheetah-Faith

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

No comments yet

Log in to join in Reading is open to everyone. Replying needs an account.