# Nesting if statements

If statements can contain other if statements within them (nesting), as shown in this example.

    value1 as integer = 0
    value2 as integer = 0
    value3 as integer = 0
    value4 as integer = 0

    do
    	print ( value1 )
    	print ( value2 )
    	print ( value3 )
    	print ( value4 )

    	if value1 + value2 + value3 + value4 < 1000
    		if value1 < 100
    			value1 = value1 + 1
    		elseif value2 < 200
    			value2 = value2 + 1
    		elseif value3 < 300
    			value3 = value3 + 1
    		elseif value4 < 400
    			value4 = value4 + 1
    		endif
    	endif

    	sync ( )
    loop

- This program declares four variables to be used as counters.
- Inside the do loop the values of these variables are displayed on screen by using the print command.
- The first if statement checks to see whether the values of all the variables are less than 1000. If they are then the block of code within this condition can be executed.
- Each variable in turn is checked to see whether is below a certain value, if so it gets 1 added to it.

When the program runs you will see value1 go from 0 to 100, then value2 will go from 0 to 200, then value3 will go from 0 to 300, finally value4 will go from 0 to 400. When all of these variables add up to 1000 the first if statement condition will be false, so nothing else happens with these variables.