maxudaskin Posted July 10, 2008 Share Posted July 10, 2008 Is it possible to break out of an if statement? I cannot use die because it finishes the execution of the whole page. How can I exit from one if statement? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I think break; works with if statements. if ($something) { //do something... break; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 There is no way to exit from an if statement, I really don't see the point in it either. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 10, 2008 Share Posted July 10, 2008 use a switch loop instead and use the break operator. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 10, 2008 Share Posted July 10, 2008 I think break; works with if statements. if ($something) { //do something... break; } break is only for: for, foreach, while, do, and switch Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Is it possible to break out of an if statement? I cannot use die because it finishes the execution of the whole page. How can I exit from one if statement? Can you show an example of why you would need to? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 10, 2008 Share Posted July 10, 2008 does seem alittle strange breaking out of an if. you use a if to test if something is correct. then it does something. if something isn't correct, then you use a else. or. you just use the if by itself. so if you dont want the script to die. The if should return false and never execute. hence, why would you need to break the if? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I think break; works with if statements. if ($something) { //do something... break; } break is only for: for, foreach, while, do, and switch Then I lied. =) Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 10, 2008 Author Share Posted July 10, 2008 <?php if(isset($_POST['login'])){ // If Login Form was Sent if(empty($_POST['user'])){ echo "You have not provided a username."; } if(empty($_POST['pass'])){ echo "You have not provided a password."; } // If user or pass are empty, exit if statement // More code including if statements } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Um, where youve got the comments, your already out of the if() statement. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 10, 2008 Share Posted July 10, 2008 add an else... Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 10, 2008 Author Share Posted July 10, 2008 Nvm... I can just add in another if statement... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.