why is htere no UNTIL loop in Powershell
-
Wednesday, October 24, 2012 7:46 PM
Powershell provides these types of loops:
DO {code} WHILE (<condition>)
DO {code} UNTIL (<condition>)
WHILE (<condition>) {code}but there is no such loop as:
UNTIL (<condition>) {code}
I started a discussion about this in the powershell forum:
but so far no definitive answer.
Thinking that the scripting guys seem to have all the answers (<grin>), I thought I'd ask here and find out.
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
All Replies
-
Wednesday, October 24, 2012 7:59 PMModerator
My guess is that the word "until" implies you're doing something at least once.
Bill
-
Wednesday, October 24, 2012 8:33 PMModerator
And why no
DONOT {code} UNTIL (<condition>)
?
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
-
Wednesday, October 24, 2012 9:26 PM
And why no
DONOT {code} UNTIL (<condition>)
?
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
We donot allow donots and coffes in this forum. It makes the keyboards sticky!
UNTIL(later){donot}
¯\_(ツ)_/¯
-
Wednesday, October 24, 2012 9:26 PM
I personally use
DON'T EVER{code}ESPECIALLY NOT IF{outrageous situation}
frequently. But it only works with "#" code markers. Oh yeah, and if the user reads the script...
-
Wednesday, October 24, 2012 9:42 PMModerator
On a serious note, perhaps you could detail the logic that you would like/expect.
Blog: http://scriptimus.wordpress.com
-
Wednesday, October 24, 2012 9:57 PM
A more serious answer: I don't know, and don't even recall it being discussed during the beta ages ago. The DO..WHILE and WHILE loops both cover all necessary conditions with negation, so there's no need for DO..UNTIL - since we have it, why not a plain UNTIL?- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Saturday, November 03, 2012 1:37 PM
- Marked As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, December 26, 2012 10:55 PM
-
Wednesday, October 24, 2012 10:00 PM
A more serious answer: I don't know, and don't even recall it being discussed during the beta ages ago. The DO..WHILE and WHILE loops both cover all necessary conditions with negation, so there's no need for DO..UNTIL - since we have it, why not a plain UNTIL?
Alex - I agree. UNTIL(then){punt}
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Wednesday, October 24, 2012 10:00 PM
-
Wednesday, October 24, 2012 10:19 PMModeratorI'll accept both of those :).
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
-
Wednesday, October 24, 2012 10:23 PMModerator
To me, "until" semantically implies you're doing something at least once, so it makes sense to me to include the until keyword for the "post test" loop case.
Bill- Edited by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, October 24, 2012 10:25 PM
- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Saturday, November 03, 2012 1:37 PM
-
Wednesday, October 24, 2012 10:43 PM
Actually UNTIL is what I believe is called teh logical contrapositive of WHILE.
WHILE( TRUE ) {...}
UNTIL(NOT TRUE){...}
These are equvalent linguistically and would evaluate as such assuming we designed the rules that way.
DO(...)UNTIL(TRUE)
Is syntactically different and implies a different purpose. It may ort may not require one execution of the body although it almost always does.
DO..UNTIL is visually clear btu UNTIL(test){...} is also visually clear and can be used as teh negation of WHILE.
Why? Symmetry is important in all systems. I can argue that adding UNTIL adds more symmetry.
The most interesting argument is that it would be a cool addition which could have interesting visual side effects.
I vote for UNTIL().
¯\_(ツ)_/¯
-
Wednesday, October 24, 2012 10:47 PM
while(-not $condition) { $condition= $true } -
Wednesday, October 24, 2012 11:06 PM
while(-not $condition) { $condition= $true }
Nope. That is not it. See the following:L
while(-not $condition)
{
"oops!"
$condition= $true
}do{
"oops!"
$condition= $true
}UNTIL($condition)Notice that they behave very differently.
UNTIL does not exisit but it would worjk like the code you posted withtout teh -not.
UNTIL($condition){$condition=$true}
Its a truthiness test and not a falsies test. Same logic, inverted sense. Lewis Carroll would be proud of you.
¯\_(ツ)_/¯
-
Thursday, October 25, 2012 2:52 AM
Al, there is no need for UNTIL. The fact that we can do
Do ... While
and
While ... Do
Covers all possibilities. As jrv noted, Until and While are logically opposite, so you'd have to put a negative in the test condition to achieve the same syntax as Until.
In other words, Do ... While is the replacement for Until, except that the condition should be "notted"
Grant Ward, a.k.a. Bigteddy
-
Thursday, October 25, 2012 6:40 AM
yeah I agree jrv, just wanted to add another variation.
UNTIL($Something){"Do stuff"} seem a bit pointless as Bigteddy says we can cover everything I can think of with what we have.
-
Thursday, October 25, 2012 9:11 AM
yeah I agree jrv, just wanted to add another variation.
UNTIL($Something){"Do stuff"} seem a bit pointless as Bigteddy says we can cover everything I can think of with what we have.
Now where is the fun in accepting the status quo? I though we were making a good case for an addition to the PowerShell language.
I say the language needs to be symmetric. Without UNTIL it is not symmetric. We should not be forced to endure a langusge that is lopsided.
Ok. As a great man once said - "We shall endeavor to persevere."
Or not!
¯\_(ツ)_/¯
-
Thursday, October 25, 2012 9:22 AM
If you are concerned about the missing UNTIL in POwerSHell what about the missing WHENEVER.
In VBScript I can create a WHENEVER condition very easily. This is not really possible in PowerShell.
Why?
Ask for an example.....(?)
¯\_(ツ)_/¯
-
Thursday, October 25, 2012 1:08 PM
While we're about it, what about a With construct, as in VB?
$os = gwmi win32_operatingsystem
with ($os) {
$name = name
$caption = caption
#etc
}
Grant Ward, a.k.a. Bigteddy
-
Thursday, October 25, 2012 3:41 PM
While we're about it, what about a With construct, as in VB?
$os = gwmi win32_operatingsystem
with ($os) {
$name = name
$caption = caption
#etc
}
Grant Ward, a.k.a. Bigteddy
PowerShell uses USING to do that kind of thing.
¯\_(ツ)_/¯
-
Thursday, October 25, 2012 3:59 PM
PowerShell uses USING to do that kind of thing.
¯\_(ツ)_/¯
Can you give an example?Grant Ward, a.k.a. Bigteddy
-
Thursday, October 25, 2012 4:13 PM
PowerShell uses USING to do that kind of thing.
¯\_(ツ)_/¯
Can you give an example?
Grant Ward, a.k.a. Bigteddy
Thought you would never ask:
http://weblogs.asp.net/adweigert/archive/2008/08/27/powershell-adding-the-using-statement.aspx
¯\_(ツ)_/¯
-
Thursday, October 25, 2012 9:45 PM
Sheesh, they say you should be careful what you ask for...
all responders so far seem to fall in one of these camps:
1. UNTIL implies the transition from false to true of the expression being tested is still in the future, so DO-UNTIL suffices
2. DO-UNTIL is not needed either, but we have it, so why not add UNTIL.
3. DO-UNTIL is not needed either, but we have it, so let's get rid of it.
4. "I though we were making a good case for an addition to the PowerShell language"
5. "If you are concerned about the missing UNTIL in POwerSHell what about the missing WHENEVER."All very interesting (and humourous comments). Those who suggested a possible rationale for there being no UNTIL statement (Bill, Alex) came closest to what I was looking for, which was not to propose any change to the language vis-a-vis UNTIL (2..4) or any other construct not present (WHENEVER, WITH, DONOT(?), etc.).
What I was actually hoping for (and still am) is the *actual* reason for the decision not to include UNTIL or, as may be more likely, the reason for it never coming into their deliberations in the first place.
In the other thread I mentioned, Larry recently reminded me that one of the really interesting aspects of Bruce Payette's book is where he explains the rationale behind some of the design decisions they made and how they developed. I would be really disappointed to hear that this simply never occurred to them, given they had already implemented DO-UNTIL.
Bill suggested that UNTIL implies at least one trip through the loop. I tend to agree that this implication is implicit in English usage. You could argue the same for the use of WHILE in the two examples I gave in the other thread:
"While you're at it, cut me a piece of pie too"
"Please watch the dog while I'm out"I mean, who would say the first thing if you did not happen to be in the process of cutting a pie, and who would say the second if they were planning on staying home.
I thing the difference is that there is a percieved quality of the condition being considered that implies that its negation is not simply a logical negation, but an imposition of a kind of NULL condition. So something is either happening or.. nothing, nada, null. WHILE asserts itself when the condition is true, but UNTIL asserts itself when the condition is not in effect, or, in otherwords, not defined.
That's the best I can come up with; and word from someone in the know?
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
-
Friday, October 26, 2012 6:13 PM
Al - Adding UNTIL would be what is soometimes referred to as 'syntactical candy'. It is somthing that can make a language more readable (self-documenting) but is not truly necessary. In PowerShell we have to elements of 'candy'; aliases and type accellerators.
Too much candy can damage a language so many designers avoid adding every logical form.
I am somewhat in favor of UNTIL but not as a replacement for DO/UNTIL. I prefer the post evaluation to be the full do...until as it seems linguistically more obvious while UNTIL() is would be the inverse of WHILE().
Maybe this is only because I like to think in an upsidedown way but it does seem sensible.
Above I think I used the term contrapositive when I should have used 'inverse'.
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Friday, October 26, 2012 6:17 PM
-
Friday, October 26, 2012 10:32 PM
All very sensible, JRV, and I tend to agree with the concept of "syntactical EYE candy".
If an UNTIL loop were added, I don't think anyone in their right mind would see it as a replacement for DO-UNTIL. After all we have WHILE and DO-WHILE.
If an UNTIL loop were added, I expect its use would account for an extremely small proportion of the four related loops, perhaps tending towards zero.
But my original question (at least the one I had in my mind) is this: is your suggested rationale the one that the powershell development team came up with to determine they were not going to include UNTIL, was there some other rationale, or was there perhaps no rationale, and they just did not think about it.
Alex might have come closest to the answer I wanted when he said: "I don't know, and don't even recall it being discussed during the beta ages ago".
I tried to ask the question of Jeffrey Snover on last nights windows server 2012 podcast, but I was stymied by poor audio reception. ;-(
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
-
Friday, October 26, 2012 11:50 PM
All I can say is don't let poor audio reception deter you. Go for it. Make Snover commit to a postion.
My impression is that "The Team" never even considered such a thing as UNTIL. Who knows? Maybe I am wrong this time but I doubt it.
¯\_(ツ)_/¯
-
Saturday, October 27, 2012 3:00 AM
well, I posted the question, but heard no answer....
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
-
Saturday, October 27, 2012 3:27 AM
well, I posted the question, but heard no answer....
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
Why Al - that sounds almost Biblical - or may maybe you just need a hearing aid?
Put another way...How can you hear no answer? Is it like the sound of one hand clapping?
¯\_(ツ)_/¯

