How can I make an event return to the start of the event list if calculations fail?

For example, if I have an event like this...

>Generate random number 1-100

>If random number is 20 or lower, do X

>X checks if Switch 001 is ON

>If Switch 001 is OFF, turn Switch 001 ON

>If Switch 001 is already ON, generate a new number.

...How do I get it to generate a new number back from the top of the event list?
I wanna say something along the lines of a loop, but I'm not an expert. But if the switch is already on, then won't it continue to generate numbers? What I'm asking is, when do you want it to stop generating numbers? That would be when you exit the loop.
Is this what you mean?

Create a map event that will activate when the player touches it.

In event commands :

Create a Control Variable to 10 store a random number 1-100.

Create a Conditional Branch directly under that command to check variable 10 is "Less than or Equal to 20".

Create your 'x' resulting process directly under that command. Eg. Show Text : "You won."

Under Else, create another process. Eg, Show Text : "You lose."  (optional)

You can check for more than one conditions using multiple conditional branches.

Hope this helps.
use a variable instead of a switch  to go through the pages 

For example, if I have an event like this...

>Random Number var == 0

>Var X == 0

when player examines event turn switch 1 on 

pg2

[if switch 1 is on]

>Generate random var number 1-100

>If random var number is 20 or lower, do X

self switch a =on

{else} 

(condition for number not being lower than 20, turn switch 1 off  set random number var 0)

End branch 

pg2 

[if self switch a is on]

>X checks if var x == (number)

>If var x not equal (number), turn Switch 2 OFF

>If Switch 2 is already OFF, Turn self switch A off, Turn Switch 1 OFF, set random number var 0.

 

or something like that 

its a little confusing because i dont know exactly what your going for but yea 
Use LABEL and JUMP TO LABEL
Here's how I would do it:

Loop

  Variable 1 = (Random: 1 through 100)

  If Variable 1 <= 20

    If Switch 1 is OFF

      Set Switch 1 to ON

      Break Loop

    End

  Else

    Break Loop

  End

Repeat Above

This assumes you don't want to select a new number if Var 1 is greater than 20 and Switch 1 is ON.  If you DO want to select a new number in this case, don't use the "Else" nor the second "Break Loop" command.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-an-event-return-to-the-start-of-the-event-list-if-calculations-fail.33409/