# Prime number identifier

# Set up initial vector

temp<-2:30

# Set up initial (empty) primes vector

primes<-NULL

### Start repeated section

for (i in temp) {

  # As the list of primes builds up we will end up with NAs
  # at the end of the temp vector. If temp[1] is NA then we
  # don't need to do any further processing in the loop.

  if(is.na(temp[1])==FALSE) {

    # copy initial number over
    
    primes<-c(primes, temp[1])

    # replace all multiples of initial number with 0

    temp<-ifelse(temp%%temp[1]==0,0,temp)

    # remove all 0 values from temp
    # - operator gets rid of everything
    # selected by the which filter

    temp<-temp[-(which(temp==0))]
    
  } # End of if statement

} # End of loop

### End repeated section

# Display the final list of primes

primes
