Search code examples
rif-statementskip

how to skip executing several lines with if clause in R


how to skip executing several lines of codes if a condition in IF statement is met. Condition happens occasionally so whenever it happens we need to skip executing several lines of codes, for example:

 if ( op=='A) {

     #skip doing everything here }
{

  #some line of codes which will be run in any condition

or is it possible to do it using while or for loops ?


Solution

  • You could test the condition using

    if (op != 'A') {
        #Code1
        #Code2
        #Don't execute this part for op == 'A' 
    }
    
    #Code3
    #Code4
    #Execute this part for everything