99 Bottles of Beer/Shell: Difference between revisions
Content added Content deleted
(autoit) |
(moving code from main task-page to sub-page / Powershell) |
||
Line 178: | Line 178: | ||
end</lang> |
end</lang> |
||
=={{header|PowerShell}}== |
|||
===A standard impementation using a For loop=== |
|||
<lang PowerShell>for($n=99; $n -gt 0; $n--) { |
|||
"$n bottles of beer on the wall" |
|||
"$n bottles of beer" |
|||
"Take one down, pass it around" |
|||
[string]($n-1) + " bottles of beer on the wall" |
|||
"" |
|||
}</lang> |
|||
===My standard implementation using for loop=== |
|||
<lang PowerShell>[int]$i = 99; |
|||
for($i=99; $i -gt 0; $i--) { |
|||
write-host $i " bottles of beer on the wall"; |
|||
write-host $i " bottles of beer"; |
|||
write-host "Take one down, pass it around" |
|||
write-host ($i-1) " bottles of beer on the wall" |
|||
write-host "" |
|||
} |
|||
</lang> |
|||
===Consolidating the static text and using a Do...while loop=== |
|||
<lang PowerShell>$n=99 |
|||
do { |
|||
"{0} bottles of beer on the wall`n{0} bottles of beer`nTake one down, pass it around`n{1} bottles of beer on the wall`n" -f $n, --$n |
|||
} while ($n -gt 0)</lang> |
|||
===Consolidating the static text and using a Do...until loop=== |
|||
<lang PowerShell>$n=99 |
|||
do { |
|||
"{0} bottles of beer on the wall`n{0} bottles of beer`nTake one down, pass it around`n{1} bottles of beer on the wall`n" -f $n, --$n |
|||
} until ($n -eq 0)</lang> |
|||
===Consolidating the static text even more=== |
|||
<lang PowerShell>$s = "{0} bottles of beer on the wall`n{0} bottles of beer`nTake one down, pass it around`n{1} bottles of beer on the wall`n" |
|||
$n=99 |
|||
do { $s -f $n, --$n } while ($n -gt 0)</lang> |
|||
===Using the Pipeline=== |
|||
<lang Powershell>99..1 | ForEach-Object { |
|||
$s=$( if( $_ -ne 1 ) { 's' } else { '' } ) |
|||
$s2=$( if( $_ -ne 2 ) { 's' } else { '' } ) |
|||
"$_ bottle$s of beer on the wall`n$_ bottle$s of beer`nTake one down`npass it around`n$( $_ - 1 ) bottle$s2 of beer on the wall`n"}</lang> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |