如何测试某个值是否在“case”范围内?语句而不是“if”陈述?
下面的 if 语句可以转换为 case 语句吗?
if (Number >= 5) and (Number <= 10) then
lblAnswer.Caption := 'in range'
else
lblAnswer.Caption := 'out of range';
我的回答:
可以
case (number >= 5) and (Number <= 10) of
lblAnswer.Caption := 'in range';
lblAnswer.Caption := 'out of range';
end;
这是正确的吗?
Can the following if statement be converted to a case statement?
if (Number >= 5) and (Number <= 10) then
lblAnswer.Caption := 'in range'
else
lblAnswer.Caption := 'out of range';
My Answer :
Yes it can
case (number >= 5) and (Number <= 10) of
lblAnswer.Caption := 'in range';
lblAnswer.Caption := 'out of range';
end;
Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 Number 具有某种整数数据类型,则:
If Number has some integer data type, then:
一个小修正:
A small correction: