checking for a range of numbers

Blitz3D Forums/Blitz3D Programming/checking for a range of numbers

slenkar(Posted 2007) [#1]
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.


Sledge(Posted 2007) [#2]
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



GfK(Posted 2007) [#3]
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



slenkar(Posted 2007) [#4]
thanks ill try them out