Ooops
November 28, 2020, 11:39:04 AM

Author Topic: [bb] Incr()/Decr() with safety check by Russell [ 1+ years ago ]  (Read 580 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Incr()/Decr() with safety check
Author : Russell
Posted : 1+ years ago

Description : Increment or decrement by a value with bounds check

Code :
Code: BlitzBasic
  1. Function Incr(iValue,iIncAmount,iMax)
  2.    If iValue + iIncAmount > iMax Then Return iMax
  3.    Return iValue + iIncAmount
  4. End Function
  5.  
  6. Function Decr(iValue,iDecAmount,iMin)
  7.    If iValue - iDecAmount < iMin Then Return iMin
  8.    Return iValue - iDecAmount
  9. End Function
  10.  
  11. x = 1
  12. For z = 1 to 20
  13. Print Incr(x,1,10) ; Will not print higher than 10
  14. Next
  15.  
  16. x = 10
  17. For p = 20 to 1
  18. Print Decr(x,3,0) ; Will not print lower than 0
  19. Next
  20.  
  21. ;Excellent for nice and neat bounds checking!


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal