I want to know what's wrong with my coding

Then a single start time is sufficient. During interval 1 (up to 10s) output_1 will be high, else during interval 2 (up to 20s) output_2 will be high, and afterwards the loop continues with the new start time.

For the change of the input see the StateChangeDetection example. If the button goes on the loop is started and going off ends the loop.