Jump to content

Execute HQ9+: Difference between revisions

Added BBC BASIC
m (→‎{{header|REXX}}: changed indentation, added/changed comments. -- ~~~~)
(Added BBC BASIC)
Line 34:
Return output
}</lang>
 
=={{header|BBC BASIC}}==
<lang bbcbasic> PROChq9plus("hq9+HqQ+Qq")
END
DEF PROChq9plus(code$)
LOCAL accumulator%, i%, bottles%
FOR i% = 1 TO LEN(code$)
CASE MID$(code$, i%, 1) OF
WHEN "h","H": PRINT "Hello, world!"
WHEN "q","Q": PRINT code$
WHEN "9":
bottles% = 99
WHILE bottles%
PRINT ;bottles% " bottles of beer on the wall, ";
PRINT ;bottles% " bottles of beer,"
bottles% -= 1
PRINT "Take one down, pass it around, ";
PRINT ;bottles% " bottles of beer on the wall."
ENDWHILE
WHEN "+": accumulator% += 1
ENDCASE
NEXT i%
ENDPROC</lang>
'''Output:'''
<pre>
Hello, world!
hq9+HqQ+Qq
99 bottles of beer on the wall, 99 bottles of beer,
Take one down, pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer,
Take one down, pass it around, 97 bottles of beer on the wall.
...
3 bottles of beer on the wall, 3 bottles of beer,
Take one down, pass it around, 2 bottles of beer on the wall.
2 bottles of beer on the wall, 2 bottles of beer,
Take one down, pass it around, 1 bottles of beer on the wall.
1 bottles of beer on the wall, 1 bottles of beer,
Take one down, pass it around, 0 bottles of beer on the wall.
Hello, world!
hq9+HqQ+Qq
hq9+HqQ+Qq
hq9+HqQ+Qq
hq9+HqQ+Qq
</pre>
 
=={{header|C}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.