This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lare290's profile picture

Printing value of variable

Started by lare290, 06 July 2015 - 04:12 PM
lare290 #1
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
KingofGamesYami #2
Posted 06 July 2015 - 06:16 PM

for i = 99, 1, -1 do
  print( i .. " bottles of beer on the wall" )
end
lare290 #3
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
meigrafd #4
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