<?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"
	>
<channel>
	<title>Comments on: Conditional Logic Using Loops</title>
	<atom:link href="http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellpro.com</link>
	<description>Sharing the Experience</description>
	<pubDate>Wed, 07 Jan 2009 00:01:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-159</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Wed, 23 Jul 2008 21:22:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-159</guid>
		<description>You're not missing anything, there was a typo in the example:
Line: if ($val -eq 30)
Should be: if ($var -eq 30)

Then you would get "30 was found in array position 3"

I've made the correction in the tutorial.</description>
		<content:encoded><![CDATA[<p>You&#8217;re not missing anything, there was a typo in the example:<br />
Line: if ($val -eq 30)<br />
Should be: if ($var -eq 30)</p>
<p>Then you would get &#8220;30 was found in array position 3&#8243;</p>
<p>I&#8217;ve made the correction in the tutorial.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-158</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Wed, 23 Jul 2008 19:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-158</guid>
		<description>Running through the second Break Statement example I get $i = 4, thus the Write-Host "30 was found in array position 4".  You wrote it should be $i = 3.  Now I won't say I'm not missing something...but what am I missing?  Thanks.</description>
		<content:encoded><![CDATA[<p>Running through the second Break Statement example I get $i = 4, thus the Write-Host &#8220;30 was found in array position 4&#8243;.  You wrote it should be $i = 3.  Now I won&#8217;t say I&#8217;m not missing something&#8230;but what am I missing?  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-150</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Mon, 14 Jul 2008 14:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-150</guid>
		<description>Jerry Lee Ford's example of getting user input is, perhaps deliberately, pointless.  The user is locked into a mode where the only valid input is "Y" whereupon the program terminates.  The only choice the user has is to delay the inevitable.  Asking "Are you sure you want to quit the application?" is kind of cheeky!</description>
		<content:encoded><![CDATA[<p>Jerry Lee Ford&#8217;s example of getting user input is, perhaps deliberately, pointless.  The user is locked into a mode where the only valid input is &#8220;Y&#8221; whereupon the program terminates.  The only choice the user has is to delay the inevitable.  Asking &#8220;Are you sure you want to quit the application?&#8221; is kind of cheeky!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FMoses</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-133</link>
		<dc:creator>FMoses</dc:creator>
		<pubDate>Wed, 18 Jun 2008 22:35:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-133</guid>
		<description>Eric,

Within the do-until loop add the following statement...essentially it puts your script to sleep for 60sec and then checks the process state every time it wakes up.  Check "get-help sleep" for more info.

{ sleep 60 }

cheers</description>
		<content:encoded><![CDATA[<p>Eric,</p>
<p>Within the do-until loop add the following statement&#8230;essentially it puts your script to sleep for 60sec and then checks the process state every time it wakes up.  Check &#8220;get-help sleep&#8221; for more info.</p>
<p>{ sleep 60 }</p>
<p>cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-121</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Fri, 30 May 2008 22:44:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-121</guid>
		<description>PowerShell doesn't require a "Next"
&lt;strong&gt;Note:&lt;/strong&gt; Those writing VBScript code will have to get use to not using "Next" as PowerShell doesn't require the keyword to move to the next item in the collection.</description>
		<content:encoded><![CDATA[<p>PowerShell doesn&#8217;t require a &#8220;Next&#8221;<br />
<strong>Note:</strong> Those writing VBScript code will have to get use to not using &#8220;Next&#8221; as PowerShell doesn&#8217;t require the keyword to move to the next item in the collection.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roshan</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-119</link>
		<dc:creator>Roshan</dc:creator>
		<pubDate>Thu, 29 May 2008 19:21:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-119</guid>
		<description>What is the keyword to move to the the next Item in a foreach ?</description>
		<content:encoded><![CDATA[<p>What is the keyword to move to the the next Item in a foreach ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-111</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Sun, 18 May 2008 19:59:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-111</guid>
		<description>The do/while approach seems to be a bad idea - powershell will peg the CPU sitting in the tight monitoring loop.
Am I missing something?</description>
		<content:encoded><![CDATA[<p>The do/while approach seems to be a bad idea - powershell will peg the CPU sitting in the tight monitoring loop.<br />
Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arlo Belshee</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-110</link>
		<dc:creator>Arlo Belshee</dc:creator>
		<pubDate>Sat, 17 May 2008 19:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-110</guid>
		<description>A quick explanation of why arrays start with 0: to decrease errors when iterating.

Basically, instead of using -le when iterating, use -lt. Then the script becomes for($i=0; $i -t ary.Length; $i++){}. You no longer have to subtrace 1 from the length. This helps reduce off by one errors.

More generally, this is an example of the half-open range concept. A half-open range with bounds 1 and 3 would be written [1, 3), and include the number {1, 2}. A closed range would include both bounds: [1, 3] means {1, 2, 3}.

The reason you care is that for non-integer data, such as decimals or dates, it is usually easier to define a range as half-open than it is as closed. For example, how do you define the time range "before noon today"? With a half-open range, you say ['5/17/2008', '5/18/2008 12:00'). With a closed range, you need to know the exact last possible momemt before noon, so that you can use it as the end of your range.

Because arrays start at 0, iterating them or selecting sub-ranges from within them uses exactly the same script as selecting sub-ranges of dates. You can just always use -lt - which means you don't have to do different things in different places, and are less likely to make mistakes.</description>
		<content:encoded><![CDATA[<p>A quick explanation of why arrays start with 0: to decrease errors when iterating.</p>
<p>Basically, instead of using -le when iterating, use -lt. Then the script becomes for($i=0; $i -t ary.Length; $i++){}. You no longer have to subtrace 1 from the length. This helps reduce off by one errors.</p>
<p>More generally, this is an example of the half-open range concept. A half-open range with bounds 1 and 3 would be written [1, 3), and include the number {1, 2}. A closed range would include both bounds: [1, 3] means {1, 2, 3}.</p>
<p>The reason you care is that for non-integer data, such as decimals or dates, it is usually easier to define a range as half-open than it is as closed. For example, how do you define the time range &#8220;before noon today&#8221;? With a half-open range, you say [&#8217;5/17/2008&#8242;, &#8216;5/18/2008 12:00&#8242;). With a closed range, you need to know the exact last possible momemt before noon, so that you can use it as the end of your range.</p>
<p>Because arrays start at 0, iterating them or selecting sub-ranges from within them uses exactly the same script as selecting sub-ranges of dates. You can just always use -lt - which means you don&#8217;t have to do different things in different places, and are less likely to make mistakes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-31</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Wed, 21 Nov 2007 20:00:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-31</guid>
		<description>Hi Ryan,
So it sounds like you want to do the opposite of what was discussed in the tutorial. You want to be notified when a process starts not stops. Easy enough...

Think about the loop type we would need to do this. In the tutorial example we use "do while" meaning run the script block while the condition is "True." What we want to do, regarding your question, is run the loop "until" notepad starts; meaning run the code-block until the condition becomes "True." For this we will use a "do until" loop.

[code]
Do{}
Until (Get-Process notepad &#124; select -Property Responding) 
$strTime = Get-Date 
Write-Host "The Application Notepad started on: $strTime"
[/code]

The code above works but there is a slight problem. Since we are running the Get-Process cmdlet and notepad is not running, we get a bunch of errors in the output. To keep it clean we need to suppress the errors in the output:

[code]
Do{}
Until (Get-Process notepad -ErrorAction SilentlyContinue &#124; Select -Property Responding) 
$strTime = Get-Date 
Write-Host "The Application Notepad started on" $strTime
[/code]


Copy this code into a .ps1 file and run the script. While the script is running launch notepad. The console output should look similar to:
The Application Notepad started on: 11/21/2007 11:51:46


Hope that helped,
Jesse Hamrick</description>
		<content:encoded><![CDATA[<p>Hi Ryan,<br />
So it sounds like you want to do the opposite of what was discussed in the tutorial. You want to be notified when a process starts not stops. Easy enough&#8230;</p>
<p>Think about the loop type we would need to do this. In the tutorial example we use &#8220;do while&#8221; meaning run the script block while the condition is &#8220;True.&#8221; What we want to do, regarding your question, is run the loop &#8220;until&#8221; notepad starts; meaning run the code-block until the condition becomes &#8220;True.&#8221; For this we will use a &#8220;do until&#8221; loop.</p>
<div class="codesnip-container" >Do{}<br />
Until (Get-Process notepad | select -Property Responding)<br />
$strTime = Get-Date<br />
Write-Host &#8220;The Application Notepad started on: $strTime&#8221;</div>
<p>The code above works but there is a slight problem. Since we are running the Get-Process cmdlet and notepad is not running, we get a bunch of errors in the output. To keep it clean we need to suppress the errors in the output:</p>
<div class="codesnip-container" >Do{}<br />
Until (Get-Process notepad -ErrorAction SilentlyContinue | Select -Property Responding)<br />
$strTime = Get-Date<br />
Write-Host &#8220;The Application Notepad started on&#8221; $strTime</div>
<p>Copy this code into a .ps1 file and run the script. While the script is running launch notepad. The console output should look similar to:<br />
The Application Notepad started on: 11/21/2007 11:51:46</p>
<p>Hope that helped,<br />
Jesse Hamrick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-30</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Wed, 21 Nov 2007 16:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/#comment-30</guid>
		<description>hay ,

just wondering if you can tell me how to use the same examples you have for waiting for a process to start ..  i can't seem to find any examples to try learn</description>
		<content:encoded><![CDATA[<p>hay ,</p>
<p>just wondering if you can tell me how to use the same examples you have for waiting for a process to start ..  i can&#8217;t seem to find any examples to try learn</p>
]]></content:encoded>
	</item>
</channel>
</rss>
