Loops/While: Difference between revisions

PowerShell
(Add new section for Lisaac)
(PowerShell)
Line 444:
endwhile;
</pre>
 
=={{header|PowerShell}}==
<lang powershell>$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>
 
=={{header|Prolog}}==
Anonymous user