是否可以将三元运算符作为for循环的终止符? [英] Is it possible to fit in a ternary operator as the termination in a for loop?

查看:95
本文介绍了是否可以将三元运算符作为for循环的终止符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我只想知道是否有可能在for循环的终止位内插入任何代码或三元运算符.如果有可能,您能否在for循环中提供一个三元运算符的示例?谢谢!

So, I just want to know if its possible to slip in any code or a ternary operator inside the termination bit of a for loop. If it is possible, could you provide an example of a ternary operator in a for loop? Thanks!

for (initialization; termination; increment) {
   statement(s)
}

推荐答案

for语句中的termination子句(如果提供-它实际上是可选的)可以是您想要的任何表达式,只要它的结果为boolean.

The termination clause in the for statement (if supplied - it's actually optional) can be any expression you want so long as it evaluates to a boolean.

它必须是一个表达式,而不是一个任意代码块.

It must be an expression, not an arbitrary code block.

这篇关于是否可以将三元运算符作为for循环的终止符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆