How can I verify that a value is within range with a case statement instead of an if statement?

Can I convert the following if statement to a case statement?

if (Number >= 5) and (Number <= 10) then lblAnswer.Caption := 'in range' else lblAnswer.Caption := 'out of range'; 

My answer:

Yes, he can

 case (number >= 5) and (Number <= 10) of lblAnswer.Caption := 'in range'; lblAnswer.Caption := 'out of range'; end; 

Is it correct?

+7
source share
3 answers

If Number has some integer data type, then:

 case number of 5 .. 10: lblAnswer.Caption := 'in range'; else lblAnswer.Caption := 'out of range'; end; 
+25
source

A small correction:

 case (number >= 5) and (Number <= 10) of true:lblAnswer.Caption := 'in range'; false:lblAnswer.Caption := 'out of range'; end; 
+6
source
 Function InRange (Lo,Hi,Val : Integer) : Boolean; Begin Result := (Val>=Lo)And(Val<=Hi); End; 
-one
source

All Articles