checking for a range of numbers
Blitz3D Forums/Blitz3D Programming/checking for a range of numbers
| ||
whats the best way to do this: check to see if a number is in the range 0>20 in the range 21>40 its quite easy to miss out numbers, I just wondered what the easiest to read method was. |
| ||
Function IntInRange(intToCheck%,startOfRange%,endOfRange%) If startOfRange<endOfRange startOfRange=startOfRange-1 endOfRange=endOfRange+1 If intToCheck < endOfRange If intToCheck > startOfRange Return True EndIf EndIf Else startOfRange=startOfRange+1 endOfRange=endOfRange-1 If intToCheck < startOfRange If intToCheck > endOfRange Return True EndIf EndIf EndIf Return False End Function |
| ||
Dunno if this works in Blitz3D, does in BlitzMax:A = Rand(0,40) Select True Case A>=0 and A<=20 ;do stuff Case A>=21 and A<=40 ;do other stuff End Select |
| ||
thanks ill try them out |