什么整数被认为是“真实的”?在 ColdFusion “if” 中陈述
在 ColdFusion 中,在 if
中哪些整数被视为 true
以及哪些整数被视为 false
陈述?我知道 1
是 true
,0
是 false
,但是是这样吗?
例如,如果知道我可以对查询数据结构的记录计数执行 if
以确定查询中是否至少有一条记录,那就太好了。例如,假设我们的查询名为 employees
。
<cfif variables.employees.recordCount>
There ARE employees.
<cfelse>
There ARE NO employees.
</cfif>
如果记录数为 2 条,是否会显示“There ARE员工”语句?
Possible Duplicate:
What are all the values that ColdFusion considers “falsy” and “truthy”?
In ColdFusion, what integers are considered true
and what integers are considered false
in an if
statement? I know that 1
is true
and 0
is false
, but is this it?
For example, it would be nice to know that I can do an if
on a query data structure's record count to determine if the query has at least one record in it. For example, let's say our query is called, employees
.
<cfif variables.employees.recordCount>
There ARE employees.
<cfelse>
There ARE NO employees.
</cfif>
Would the statement "There ARE employees" be displayed if the record count was, say, 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何非零数都是真的。只有 0 才会返回 false。
Any non zero number is true. Only 0 will return false.
所以看起来 0 代表 false,或者其他任何值代表 true整数。
So it looks like 0 is for false, or anything else for true in the case of integers.
非常相似的问题:
ColdFusion 认为“虚假”的所有值是什么” 和“truthy”?
关于如何在 ColdFusion 中评估变量的真实性的大量博客文章:
ColdFusion 认为“虚假”的所有值是什么”和“真实”?
Very similar question:
What are all the values that ColdFusion considers "falsy" and "truthy"?
Extensive blog post about how variables are evaluated for truthiness in ColdFusion:
What are all the values that ColdFusion considers "falsy" and "truthy"?