简体   繁体   English

该条件(常规脚本)的返回值是多少?

[英]What is the return value of this conditional (groovy script)

What will be the return value of this if/else statement? if/else语句的返回值是多少?

if (salary <= 3000) {
  return discount < 0.40
}
else {
  return discount < 0.60
}

I'm not sure if the return value of each if and else will be a boolean or 0.40 and 0.60 ? 我不确定每个ifelse的返回值是boolean还是0.400.60

It is a boolean. 这是一个布尔值。 The < , > , != , >= , == , <= expressions will evaluate to a boolean value: <>!=>===<=表达式将计算为布尔值:

def mustDiscount(salary, discount = 0.5) {
    if (salary <= 3000) {
      return discount < 0.40
    }
    else {
      return discount < 0.60
    }
}

mustDiscount(2000).with {
    assert it in Boolean
    assert !it
}


mustDiscount(4000).with {
    assert it in Boolean
    assert it
}

The return type for that would be a boolean (true or false), both in the if block and else block. 在if块和else块中,其返回类型均为布尔值(true或false)。

Also return discount == 0.50 would return a boolean. 同样,如果return discount == 0.50 ,则返回布尔值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有返回值的条件运算符 - Conditional operator without return value np选择if语句以返回条件语句的值 - np select if statement to return a value for a conditional statement 在批处理脚本中执行此条件(if-else)有什么问题? - what is wrong with this conditional (if-else) execution in batch script? 如果 output 是一个数字,我怎样才能使这个有条件的返回一个值? - How can i make this conditional return a value IF the output is a number? 收集Groovy中的自定义数字字段,并计算返回结果(JIRA脚本运行器) - Gathering custom number fields in Groovy, and calculating return result (JIRA script runner) 基于Groovy Result响应的条件转到 - Conditional Goto based on Groovy Result response 值的条件分配 - 当条件和预期返回值没有相同的功能时, ifelse() 是最好的吗? [R] - Conditional assignment of value - is ifelse() the best when condition and intended return value don't have same features? [R] 什么意味着Linux脚本中的if表达式中的-z值? - What means the -z value in an if expression on a Linux script? 如果在SQL Script for Mysql中有条件 - If conditional in SQL Script for Mysql 从 Run Keyword If 条件 Robot Framework 中获取关键字的返回值 - Get return value from keyword from within Run Keyword If conditional Robot Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM