开始使用免费开始使用

If 这样,Else 那样

if 语句的一个扩展是在条件为假时执行不同的操作。您可以在 if 语句后添加 else 来实现:

if(condition) {
    code if true
} else {
    code if false 
}

本练习是课程的一部分

R 金融中级

查看课程

练习说明

  • 在上一个练习的基础上,添加一个 else 分支,并打印 "Do nothing!"

交互式实操练习

通过完成这段示例代码来试试这个练习。

micr <- 57.44

# Fill in the blanks
if( micr < 55 ) {
    print("Buy!")
} ___ {
    ___
}
编辑并运行代码