Groovy If语句
2018-12-29 14:19 更新
第一个决策语句是 if 语句。这种说法的一般形式是 -
if(condition) {
statement #1
statement #2
...
}
这个语句的一般工作是首先在 if 语句中评估一个条件。如果条件为真,它然后执行语句。下图显示了 if 语句的流程。

下面是一个if / else语句的例子 -
class Example {
static void main(String[] args) {
// Initializing a local variable
int a = 2
//Check for the boolean condition
if (a<100) {
//If the condition is true print the following statement
println("The value is less than 100");
}
}
}
在上面的例子中,我们首先将一个变量初始化为值2.然后我们评估变量的值,然后决定是否应该执行 println 语句。上面的代码的输出将是 -
The value is less than 100
以上内容是否对您有帮助:

免费 AI IDE


更多建议: