exit loop

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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

exit loop

Post by shiznatix »

i was wonder if there was a way to exit a for loop after one variable is equal to the other, i want the script to continue but i just want the loop to stop right there and then go to the next part of the script.

example:

Code: Select all

$arrview = explode(",", $notviewd);
		$countview = count($arrview);
		for ($i=0; $i<$countview; $i++)&#123;
		echo $arrview&#1111;$i].' ';
			if ($arrview&#1111;$i] == $threadid)&#123;
				if ($reply_count > '9')&#123;
				echo "<img src='img/new_post_hot.gif'>";
      //exit loop here
				&#125;
				if($accesslvl == '1')&#123;
				echo "<img src='img/new_post_lock.gif'>";
      //exit loop here
				&#125;
				if($reply_count < '9')&#123;
				echo "<img src='img/new_post.gif'>";
      //exit loop here
				&#125;
			&#125;
		&#125;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

break;

:roll:

since you'll probably ask later: continue;

you'll understand when you come to the question :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

affirmative, thanks
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

or you could put

$i=$countview;

then it wouldnt loop anymore
Post Reply