Repeating a step until conditions are met?

How would I repeat a part of a script until certain conditions are met? For example, a user inputs some text, the script compares it with a variable, and if they don’t match, the user is presented with “cancel” and “try again”. I want the “try again” button to bring them back to where they input the text. Would this be done with a “try” or “repeat” or something? I can’ have it go back to the beginning of the script, just the block that is doing this function.

Thanks!

I think you want something like this:

set flag to true
repeat while flag is true
	-- do your stuff
	display dialog "Do you want to stop or try again?" buttons {"Stop", "Try Again"} default button "Try Again"
	if button returned of result = "Stop" then set flag to false
end repeat

Thank you.