Jump to content

Loops/While: Difference between revisions

348 bytes removed ,  13 years ago
→‎{{header|PowerShell}}: slightly less confusing example
(added PostScript)
(→‎{{header|PowerShell}}: slightly less confusing example)
Line 653:
 
=={{header|PowerShell}}==
<lang powershell>[int]$i = 1024
while ($i -gt 0) {
$i
$i /= 2
}</lang>
Since PowerShell automatically converts variables to other types to accommodate for operations the above loop does not stop at 1 like it would in other languages but loops for quite a while until the value is small enough to be considered 0. An explicit cast corrects this:
<lang powershell>$i = 1024
while ($i -gt 0) {
$i
[int]$i /= 2
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.