how to make a dialog syncronouos?

I have an app where the user clicks a button, a dialog comes up asking for confirmation. Based on their selection I update a variable and execute the rest of the code based on the variable value. The problem is that the code that follows always executes before the user presses the button. How can I fix this so everything executes in a linear manner?