Search code examples
rfor-loopbreakenter

How to use ENTER as user input


I have a for loop and I want it to only go to the next "i"-value when you hit enter in the console. So I wrote this:

for (i in 1:5){
 print(i) 
 UserInput <- readline(prompt = "Press enter to continue.")
 if (UserInput != "ENTER"){ #Obviously "ENTER" is incorrect, but something like that. 
  break
 }
}

Any clues?


Solution

  • A simple solution is:

    for (i in 1:5){
        readline(prompt=i) }