1

Is it possible in a GnuPlot 5.2 script, to break out of a loop on a (certain) key being pressed?

do for [m=1:6] {      
  do for [i=1:3] {
     do for [fr=0:25] {
        splot 'ex.plt' using 2:3:4 w l lt 1, sprintf("'exm%d.%d'",m,fr)  using 1:2:3 w l lt 3
        set view 69.867, 100.267, 2.503 
        pause 0.05
        break # however: conditionally, on key pressed
     }
  }
}
# break to here

1 Answer 1

3

Check help bind. Probably, you are looking for something like this. In this example, the loop will stop when x is pressed.

Script:

### key bind to stop a loop
reset session

bind "x" "Stop = 1"
Stop = 0

do for [i=1:50] {
    plot sin(i/20.*x)
    print i
    pause 0.1
    if (Stop) {Stop = i;  break}
}

if (Stop) { print sprintf("Stopped after %d iterations", Stop) }
else      { print "Time is over..." }
### end of script
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.