如何使用R中的if子句跳过执行多行
如果满足if语句中的条件,如何跳过执行几行代码。这种情况偶尔会发生,因此无论何时发生,我们都需要跳过执行几行代码,例如:如何使用R中的if子句跳过执行多行,r,if-statement,skip,R,If Statement,Skip,如果满足if语句中的条件,如何跳过执行几行代码。这种情况偶尔会发生,因此无论何时发生,我们都需要跳过执行几行代码,例如: if ( op=='A) { #skip doing everything here } { #some line of codes which will be run in any condition 或者可以使用while或for循环来完成吗 您可以使用下一个关键字。例如,下面的代码将不会打印 向量x=1:10,从5到8的值: 您可以使用 if (o
if ( op=='A) {
#skip doing everything here }
{
#some line of codes which will be run in any condition
或者可以使用while或for循环来完成吗 您可以使用下一个关键字。例如,下面的代码将不会打印
向量x=1:10,从5到8的值:
您可以使用
if (op != 'A') {
#Code1
#Code2
#Don't execute this part for op == 'A'
}
#Code3
#Code4
#Execute this part for everything
我不明白,你似乎已经明白了。问题在哪里?我需要跳过执行那些行,而不是执行它们的块,这是我不知道的。如果使用If op!='当op==A时,将不执行“跳过此处所有操作”部分。
x = 1:10
for(i in x){
if(i>=5 && i<=8){
next #Skips printing when i=5,6,7 and 8
}
print(i) #Code you don't want skipped goes here
}
if (op != 'A') {
#Code1
#Code2
#Don't execute this part for op == 'A'
}
#Code3
#Code4
#Execute this part for everything