如果条件如下,我必须重复编写 else:
if (d_hand[1]==1){
state=score(p_hand)-1
} else if (d_hand[1]==2){
state=19+score(p_hand)
} else if (d_hand[1]==3){
state=39+score(p_hand)
} else if (d_hand[1]==4){
state=59+score(p_hand)
} else if (d_hand[1]==5){
state=79+score(p_hand)
} else if (d_hand[1]==6){
state=99+score(p_hand)
}
你知道它是否可以写得更高效/更短吗? 我想过做一个 if 循环,但效率会降低,因为必须检查每个语句。
最佳答案
根本没有ifelse
:
state <- score(p_hand) + 20 * d_hand[1] - 21
关于r - 重复 else if 语句的快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49676353/