if循环

2023-10-27 15:36:20 浏览数 (2)

if...else...

代码语言:javascript复制
// 输入代码内容
if(i>0){
    print"success"
}else{
    print"defaet"
}

ifelse

代码语言:javascript复制
// 输入代码内容
ifelse(i>0,"success","defeat")

#ifelse 嵌套

ifelse(i>0,print"i>0",ifelse(i<0,"i<=0","0"))

联合ifelse str_detect

代码语言:javascript复制
// 输入代码内容
samples=c("abc","bbc","cbc")
k1=str_detect(samples,"a")
ifelse(k1,"带有a","不带有a")

多循环

代码语言:javascript复制
// 输入代码内容
if (i>0){
  print(' ')
} else if (i==0) {
  print('0')
} else if (i< 0){
  print('-')
}

0 人点赞