<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Break not working in ForEach</title>
	<atom:link href="http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/feed/" rel="self" type="application/rss+xml" />
	<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/</link>
	<description>Dmitry Sotnikov's view on PowerShell, PowerGUI and everything he sees around</description>
	<lastBuildDate>Mon, 30 Nov 2009 16:13:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Episode 85 &#8211; Lee Holmes talks about v2 &#171; PowerScripting Podcast</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5281</link>
		<dc:creator>Episode 85 &#8211; Lee Holmes talks about v2 &#171; PowerScripting Podcast</dc:creator>
		<pubDate>Mon, 28 Sep 2009 04:24:19 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5281</guid>
		<description>[...] Break doesn&#8217;t work in pipelines [...]</description>
		<content:encoded><![CDATA[<p>[...] Break doesn&#8217;t work in pipelines [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karl prosser</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5277</link>
		<dc:creator>karl prosser</dc:creator>
		<pubDate>Wed, 23 Sep 2009 15:13:11 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5277</guid>
		<description>I personally think Break has a wrong design, and is a liability to solid code and should really just be avoided in PowerShell. Even the scenarios where its perfectly safe is not worth it IMO</description>
		<content:encoded><![CDATA[<p>I personally think Break has a wrong design, and is a liability to solid code and should really just be avoided in PowerShell. Even the scenarios where its perfectly safe is not worth it IMO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry Sotnikov</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5276</link>
		<dc:creator>Dmitry Sotnikov</dc:creator>
		<pubDate>Wed, 23 Sep 2009 08:44:10 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5276</guid>
		<description>Good point Karl! Break can be very confusing indeed.</description>
		<content:encoded><![CDATA[<p>Good point Karl! Break can be very confusing indeed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karl prosser</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5275</link>
		<dc:creator>karl prosser</dc:creator>
		<pubDate>Tue, 22 Sep 2009 21:00:38 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5275</guid>
		<description>Break in powershell is dangerous as it just throws an exception, and if in a scriptblock, it will just bubble up to the nearest thing in the pipeline, a cmdlet or whatnot and the result will be unpredicatable or at least inconsistant.</description>
		<content:encoded><![CDATA[<p>Break in powershell is dangerous as it just throws an exception, and if in a scriptblock, it will just bubble up to the nearest thing in the pipeline, a cmdlet or whatnot and the result will be unpredicatable or at least inconsistant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Powershell Newbie</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5223</link>
		<dc:creator>Powershell Newbie</dc:creator>
		<pubDate>Fri, 28 Aug 2009 17:55:26 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5223</guid>
		<description>It is a bit frustrating that this has been my workaround for the other issue I ran into and has to be again worked around. 

Thanks for your information.  I will take a look at the links.

Newbie</description>
		<content:encoded><![CDATA[<p>It is a bit frustrating that this has been my workaround for the other issue I ran into and has to be again worked around. </p>
<p>Thanks for your information.  I will take a look at the links.</p>
<p>Newbie</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry Sotnikov</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5220</link>
		<dc:creator>Dmitry Sotnikov</dc:creator>
		<pubDate>Thu, 27 Aug 2009 07:48:56 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5220</guid>
		<description>You are right - break only breaks the current scope and return only returns from the current function (again, not the full recursion).

You can use &quot;throw&quot; to generate an exception and this will get you from the whole thing. The tricky part is that this will by default terminate the whole script - not just the function. This might or might not be what you need.

If this is not what you need, and you do need to proceed from some place - you need to catch the exception there.

Unfortunately, catching that exception so the script does not terminate at all is not that easy in PowerShell v1. In v2, it is as easy as enclosing the original function call in try/catch.

If you need more information, I would as in the forums at http://powergui.org</description>
		<content:encoded><![CDATA[<p>You are right &#8211; break only breaks the current scope and return only returns from the current function (again, not the full recursion).</p>
<p>You can use &#8220;throw&#8221; to generate an exception and this will get you from the whole thing. The tricky part is that this will by default terminate the whole script &#8211; not just the function. This might or might not be what you need.</p>
<p>If this is not what you need, and you do need to proceed from some place &#8211; you need to catch the exception there.</p>
<p>Unfortunately, catching that exception so the script does not terminate at all is not that easy in PowerShell v1. In v2, it is as easy as enclosing the original function call in try/catch.</p>
<p>If you need more information, I would as in the forums at <a href="http://powergui.org" rel="nofollow">http://powergui.org</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Powershell Newbie</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5219</link>
		<dc:creator>Powershell Newbie</dc:creator>
		<pubDate>Thu, 27 Aug 2009 06:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5219</guid>
		<description>&quot;break&quot; used in the following recursive function only breaks out of the current iteration of the recursion instead of the complete recursion.  I already tried to use &quot;return&quot; but it did not help.  Any idea how I can break out of the recursive function?

function find-file( $startfolder, $nameoffile )
{
   foreach ( $_ in get-childitem $startfolder ) { 
	if( $_ -match $nameoffile ) 
	{
		Write-Host &quot;Found the file, assigning the file path to a variable...&quot;
		$FilePath = $_.FullName
		break
	} else {
		if( $_.PsIsContainer )
		{
			find-file $_.FullName $nameoffile
		}
	}
   }
}</description>
		<content:encoded><![CDATA[<p>&#8220;break&#8221; used in the following recursive function only breaks out of the current iteration of the recursion instead of the complete recursion.  I already tried to use &#8220;return&#8221; but it did not help.  Any idea how I can break out of the recursive function?</p>
<p>function find-file( $startfolder, $nameoffile )<br />
{<br />
   foreach ( $_ in get-childitem $startfolder ) {<br />
	if( $_ -match $nameoffile )<br />
	{<br />
		Write-Host &#8220;Found the file, assigning the file path to a variable&#8230;&#8221;<br />
		$FilePath = $_.FullName<br />
		break<br />
	} else {<br />
		if( $_.PsIsContainer )<br />
		{<br />
			find-file $_.FullName $nameoffile<br />
		}<br />
	}<br />
   }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Argenis Fernandez</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5046</link>
		<dc:creator>Argenis Fernandez</dc:creator>
		<pubDate>Tue, 09 Jun 2009 19:23:41 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-5046</guid>
		<description>Thanks for the post. Nice to know.</description>
		<content:encoded><![CDATA[<p>Thanks for the post. Nice to know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Essential PowerShell: Understanding foreach (Addendum) &#171; Poshoholic</title>
		<link>http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-997</link>
		<dc:creator>Essential PowerShell: Understanding foreach (Addendum) &#171; Poshoholic</dc:creator>
		<pubDate>Sat, 01 Sep 2007 00:00:53 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysotnikov.wordpress.com/2007/08/31/break-not-working-in-foreach/#comment-997</guid>
		<description>[...] Dmitry Sotnikov discovered first-hand and blogged about earlier today, there is another important difference between what might appear as two similar constructs in [...]</description>
		<content:encoded><![CDATA[<p>[...] Dmitry Sotnikov discovered first-hand and blogged about earlier today, there is another important difference between what might appear as two similar constructs in [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
