Count in octal: Difference between revisions
Content added Content deleted
m (Fix lang example: Fix while condition) |
No edit summary |
||
Line 2,097: | Line 2,097: | ||
print(string.format("%o",l)) |
print(string.format("%o",l)) |
||
end</syntaxhighlight> |
end</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
|||
<syntaxhighlight lang="m2000 interpreter"> |
|||
Module CountInOctal { |
|||
class OctalDigitsCounter { |
|||
private: |
|||
dim m() as byte |
|||
public: |
|||
Last as boolean |
|||
Value { |
|||
string s1 |
|||
integer i |
|||
for i=len(.m()) to 1 |
|||
s1+=.m(i) |
|||
next |
|||
=s1 |
|||
} |
|||
Set (s as OctalDigitsCounter) { |
|||
.m()=s.m() |
|||
.Last<=false |
|||
} |
|||
Operator "++" { |
|||
integer z=0, i=1, h=len(.m()), L=h+1 |
|||
if valid(.last) else error "problem" |
|||
while i<L |
|||
if .m(i)>=7% then z++:.m(i)=0:i++ else L=i:.m(i)++ |
|||
end while |
|||
if z=H then .last<=true |
|||
} |
|||
class: |
|||
Module OctalDigitsCounter(Digits as long) { |
|||
if Digits<1 then Error "Wrong number for Digits" |
|||
dim .m(1 to Digits) |
|||
} |
|||
} |
|||
// set digits to number of character width of console |
|||
k=OctalDigitsCounter(width) |
|||
// or set to 3 digits |
|||
Rem : k=OctalDigitsCounter(3) |
|||
// you can press Esc to stop it |
|||
escape off |
|||
refresh 100 // to synchronize the scrolling, so we always see the numbers not the empty line |
|||
while not k.last |
|||
print part $(0), k // print without new line, $(0) used for non proportional character printing |
|||
refresh // so we do a refresh here before the scrolling which do the next print statement |
|||
print |
|||
k++ |
|||
if keypress(27) then exit |
|||
end while |
|||
print |
|||
escape on |
|||
print "done" |
|||
} |
|||
CountInOctal |
|||
</syntaxhighlight> |
|||
=={{header|M4}}== |
=={{header|M4}}== |