title: Terminating an apply-based function early (similar to break?)
body: <p>I am searching for a way to terminate an apply function early on some condition.  Using a for loop, something like:</p>
  
  <pre><code>FDP_HCFA = function(FaultMatrix, TestCosts, GenerateNeighbors, RandomSeed) {    
    set.seed(RandomSeed)
  
    ## number of tests, mind the summary column
    nT = ncol(FaultMatrix) - 1
    StartingSequence = sample(1:nT)
    BestAPFD = APFD_C(StartingSequence, FaultMatrix, TestCosts)
    BestPrioritization = StartingSequence
    MakingProgress = TRUE
    NumberOfIterations = 0
    while(MakingProgress) {
      BestPrioritizationBefore = BestPrioritization
      AllCurrentNeighbors = GenerateNeighbors(BestPrioritization)
  
      for(CurrentNeighbor in AllCurrentNeighbors) {
        CurrentAPFD = APFD_C(CurrentNeighbor, FaultMatrix, TestCosts)
  
        if(CurrentAPFD &gt; BestAPFD) {
          BestAPFD = CurrentAPFD
          BestPrioritization = CurrentNeighbor            
          break
        }
      }
  
      if(length(union(list(BestPrioritizationBefore),
                      list(BestPrioritization))) == 1)
        MakingProgress = FALSE
  
      NumberOfIterations = NumberOfIterations + 1
    }
  }
  </code></pre>
  
  <p>I would like to rewrite this function using some derivation of <code>apply</code>. In particular, terminating the evaluation of the first individual with increased fitness, thereby avoiding the cost of considering the rest of the population.  </p>