Break an IF Statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Break an IF Statement

Post by AliasBDI »

Is it possible to break out of an IF statement like this ...

Code: Select all

 
if (condition) {
  if (condtion) {
    //break out to first conditions else...
  }
} else {
  //do this..
}
 
 
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: Break an IF Statement

Post by lafever »

What are you using this for? Are there reasons to not using elseif? If an if statement returns false it's just ignored anyways.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Break an IF Statement

Post by Christopher »

There is no breaking out in the sense of a loop, but you can certainly construct the logic to control what is done, and not done, under specific conditions:

Code: Select all

if (condition1) {
  if (condtion2) {
    // code that meets both condition1 and condition2 will run here
  }
} else {
  //do this if not condition1, but still could be condition2
}
(#10850)
Post Reply