The word "if" is used, signifying a choice that had to be made. God knowing the hearts of all men beforehand, knew Pharaoh's heart, and He knew forcing Pharaoh to make a decision would harden Pharaoh's heart. Thus it was God's command to let the people go, that hardened Pharaoh's heart. In each case where Pharaoh was given two alternatives, there was no judgement until after Pharaoh made a choice.
The foreknowledge of God is not to be mistaken for no choice. Even though God knows beforehand what the choice will be; else, why would He say, "Choose ye this day whom you will serve. God brings judgement after actions; indeed, why should he wait, or why offer choices at all if no decisions are to be made by those given a choice of two different fates?
Foreknowledge (or foreknown) isn't that God looks down some tunnel to see what people will do as many seem to believe. Rather foreknowledge is God deliberately purposes what He wants by His sovereign will and predestines that will. (He knows what He wants to do ahead of time (foreknown) and then He decrees it so (predestined).)
Pharaoh is a good example. God knew very well that Pharaoh wouldn't "chose" to let the people go until enough pressure had been put upon him. Yet God constantly asks him to. It is a puzzlement but this is what the scriptures teaches and we cannot understand the mind of God. Only that He is just and fair in all that He does. We just take the things that are revealed to us and rightfully understand the truth so we can understand God and His word.
Deuteronomy 29:29 The secret things belong to the Lord our God, but the things revealed belong to us and to our sons forever, that we may observe all the words of this law.