If – elseif – else

Views: 11 Last modified: July 31st, 2011 Comments: 1

if – elseif – else

Well, this is the tutorial for a if – elseif – else statement. I just assume that you’re already familiar with the if construct and the else statement. Now, i will explain the elseif part, as it might be very useful for you.

Example if – elseif – else

if (expression)
{
	// Code if true
}
elseif (expression)
{
	// Code if true
}
elseif (expression)
{
	 // Code if true
}
else
{
	// Code if all are false
}

So, as you can see, there is not only a if and else statement present. Now we have the elseif as well. The deal here is just that you can provide expressions for each of the elseif statements. For each of the expressions a block of code is reserved between the accolades ({ }). If the expression evaluates true, the code between the { and } will be performed by the php engine. If all the expressions evaluates false, the (already known) else statement will take the lead and will be performed by the php engine.

Moreover, you can add as many elseif statements as you like, without having limitations. Unfortunately how more you are using, how more confusing it will be if you don’t write on a decent manner. Therefor i personally recommend the switch statement, but that’s not really the subject here isn’t it…..

Well, this is pretty simple right ? :)

Some more examples

if (5 > 6)
{
	// Code if true
}
elseif (5 == 6)
{
	// Code if true
}
elseif (5 != 6)
{
	 // Code if true
}
else
{
	// Code if false
}
if (5 > 6):
	// Code if true
elseif (5 == 6):
	// Code if true
elseif (5 != 6):
	 // Code if true
else:
	// Code if false
endif;
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
    Bluehost

    Mail this!

    To: From:Sum {3+7} =  
    1. Thank you. – behindvfx
    Anything to add ?

        You must be logged in to post a comment.