目录

if statement

if语句由一个布尔表达式后跟一个或多个语句组成。

语法 (Syntax)

在R中创建if语句的基本语法是 -

if(boolean_expression) {
   // statement(s) will execute if the boolean expression is true.
}

如果布尔表达式的计算结果为true ,则将执行if语句中的代码块。 如果布尔表达式的计算结果为false ,则将执行if语句结束后(在结束大括号之后)的第一组代码。

流程图 (Flow Diagram)

R if语句

例子 (Example)

x <- 30L
if(is.integer(x)) {
   print("X is an Integer")
}

编译并执行上述代码时,会产生以下结果 -

[1] "X is an Integer"
↑回到顶部↑
WIKI教程 @2018