Reading the position of a flex sensor to set a limit

The logic sounds simple

start of loop()
  if the button is pressed
    read the flex sensor and save the value to a variable
  end if

  read the flex sensor
  if the value is greater than the saved value
    execute the code here
  end if
end of loop()