First of all let's pretend we want the user to guess a secret number. If the number is too big then we want to display a dialog box saying "Sorry dude, your choice is too big". If the number is too small, then we want to say "Sorry dude, your choice is too small". Finally, if they guess the number then we should say "Hurrah! You got it!".

This can be done using a special construct called if - then - else. The if statement has the following syntax in python. It is also known as a selection statement as it changes the flow of a program.


if  :
	#code is placed here 



The condition is a test which must evaluate to true of false. If the condition is true then we run the code inside the if statement. Otherwise we do nothing.


If 4 == 4 : 
	print "4 = 4. We have a genius on our hands here!"



The above code shows a simple example of a conditional test. We are testing to see if the number 4 equals the number 4. Clearly it does, so we run the code held inside the If statement. Anything which is in between the IF and END IF statements will be run if the condition turns out to be true.

Notice that we have the condition 4 = 4. In the last section we saw that the equals sign, =, is the assignment operator and used to assign values to variables. Unfortunately in VB it also can mean equal to in a condition. So the above if statement reads "If 4 is equal to 4" rather than "If 4 is assigned to ". This is a little confusing for a lot of new programmers. Just remember to look at the context in which it appears.

Comparisons

Else