Talk:Loops/While: Difference between revisions

m
added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).
(→‎DC: new section)
m (added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).)
 
(3 intermediate revisions by one other user not shown)
Line 1:
== number should be INT ? ==
 
Perhaps it should be specified that the number should be int or the number to count down to should be '1' rather than '0' The reason is that for languages that support the numbers rather than integers, the value only tends towards '0' never reaching it :)
 
Line 52 ⟶ 54:
</pre>
A WHILE should test first and execute the body only if the test succeeded.
 
Alternative version (needs review, comment, adopt, ...):
 
{{works with|GNU Dc}}
{{works with|OpenBSD Dc}}
If the comments are omitted: {{works with|AT&T Dc}}
<pre>
$ dc<<end
[ q ] sQ # makro Q : quit 2 levels (quit Q and calling level)
1024 [ d 0!<Q # compare, quit if true
p 2 / # print and divide
lW x # tail recursion
] d sW x # duplicate store as W execute TOS
end
1024
512
256
128
64
32
16
8
4
2
1
</pre>
 
--[[User:Yeti|Yeti]] ([[User talk:Yeti|talk]]) 04:42, 26 November 2018 (UTC)