64 posts
Location
Finland
Posted 06 July 2015 - 06:12 PM
How to make computer print value of variable? I'm trying to make Hello world-style program using 99 Bottles of Beer and loop, but don't remember how to print value of variable. Like if variable is bottlenumber, and then computer should print bottlenumber + "bottles of beer on the wall". Then make bottlenumber -1 etc.
Edited on 06 July 2015 - 04:13 PM
3057 posts
Location
United States of America
Posted 06 July 2015 - 06:16 PM
for i = 99, 1, -1 do
print( i .. " bottles of beer on the wall" )
end
64 posts
Location
Finland
Posted 06 July 2015 - 06:18 PM
Oh, I was trying to do
bottlenumber = 99
while bottlenumber > 0 do
print(bottlenumber "bottles of beer on the wall, then you take 1 away")
if bottlenumber == 0 then
print("no more bottles, gotta buy more")
end
end
Didn't remember for-loop :unsure:/>
Edited on 06 July 2015 - 04:23 PM
17 posts
Location
Germany
Posted 06 July 2015 - 06:36 PM
You also can use:
var = "foo"
print(var, "bar")
But BTW your while will not work as aspected ;)/>
The while will only run till bottlenumber is 1 but stops when its 0 (while bottlenumber is bigger than 0), so your 'if' will never get executed solang its inside the while.. Put it after it and all is fine :)/>
Edited on 06 July 2015 - 04:42 PM