Jump to content
xisto Community
alex1985

Endif function?

Recommended Posts

As you get noticed before, I am studying PHP in examples like using the tutorials as well as books itself. Through my readings, I get this function

<?php endif; ?>
a lot of times. So, what do you mean by this function, and what does it do exactly?

Share this post


Link to post
Share on other sites

More often than not I would use the {} instead of the endif statement. It is just redundant in my opinion. So it would look something like this:

<?php if ($number == 1) {		----some code here----}<?php>

Share this post


Link to post
Share on other sites

Looks like something you'd see in Python. But i've been spoiled by the curly brackets. <_< It's so much quicker to type curly brackets, which is why i haven't taken the time to learn Python.

Share this post


Link to post
Share on other sites

There are three ways to write an if statement depending on what you want to do and what your coding style is like. I shall give examples below:

 

"Standard" If Statement

This is your bog standard if statement, used millions of times by pretty much everyone:

 

if ( condition ) {	code to execute if condition === TRUE}

If the condition is true then the code between the curly braces - { } - gets run. If the condition is false then the code between the curly braces is ignored.

 

"Verbose" If Statement

This is the slightly longer/older style if statement. It is more similar to if statements in older programming languages.

 

if ( condition ) :	Code here is executed if condition === TRUEendif;

Here the code that gets run if the condition is true starts with a colon : and ends with endif;

This is sometimes useful to use if there are lots of curly braces dotted around your script, as it makes clear exactly what you are closing (if, while, else, foreach, etc.).

 

"Short" If Statement

This is used to execute one command, and only one command, when the condition is true. It has no real start or end, and is simply made up with the if statement. Whatever the next line is is only executed when the condition is true.

 

if ( condition )	This line gets executed if condition === TRUE;This line is always run;So is this one;

The line that is part of the if statement usually gets indented to make it clearer that it is only run when the if statement is true.

 

You might want to take a look at the following two manual pages for more information about exactly how they work if it still isn't totally clear:

http://forums.xisto.com/no_longer_exists/

http://forums.xisto.com/no_longer_exists/

Share this post


Link to post
Share on other sites

There are three ways to write an if statement depending on what you want to do and what your coding style is like. I shall give examples below:

 

"Standard" If Statement

This is your bog standard if statement, used millions of times by pretty much everyone:

 

if ( condition ) {	code to execute if condition === TRUE}

If the condition is true then the code between the curly braces - { } - gets run. If the condition is false then the code between the curly braces is ignored.

 

"Verbose" If Statement

This is the slightly longer/older style if statement. It is more similar to if statements in older programming languages.

 

if ( condition ) :	Code here is executed if condition === TRUEendif;

Here the code that gets run if the condition is true starts with a colon : and ends with endif;

This is sometimes useful to use if there are lots of curly braces dotted around your script, as it makes clear exactly what you are closing (if, while, else, foreach, etc.).

 

"Short" If Statement

This is used to execute one command, and only one command, when the condition is true. It has no real start or end, and is simply made up with the if statement. Whatever the next line is is only executed when the condition is true.

 

if ( condition )	This line gets executed if condition === TRUE;This line is always run;So is this one;

The line that is part of the if statement usually gets indented to make it clearer that it is only run when the if statement is true.

 

You might want to take a look at the following two manual pages for more information about exactly how they work if it still isn't totally clear:

http://forums.xisto.com/no_longer_exists/

http://forums.xisto.com/no_longer_exists/


Oh, thanks. It's clear now!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.