Expect - Comparison of expect value and loop selection

Hello All,
I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation.
For Example if this is a first time installation then at step 3 I'll get "Do you want to accept this agreement [y/n]: and then step 4 and 5 but if it is a 2nd time installation then I'll get from step 5 directly.

For 1st time installation
............
(step -3) expect "n]:" {send "yes\r" }
(step -4) expect "q):" {send "5\r"}
(step -5) expect "net):" {send "xyz\r"}

For 2nd time installation
............. (Previosu 2 steps will not be available)
(step -5) expect "net):" {send "xyz\r"}

So is it possible to somehow compare the expected output and according to that I can provide my inputs, so that same script can work for irrespective of the input.
I have searched in the Google but not able to get any answer.
Any help appreciated with examples.

Thanks