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

For loop help

Started by NoirVinoCacao, 26 October 2012 - 02:33 PM
NoirVinoCacao #1
Posted 26 October 2012 - 04:33 PM
i want to create a for loop that loops a userdifined amount of times and I am having trouble with it.

what i have so far is(im only going to post the relevant part of the code btw)

Spoiler

ntimes = read()
for i = 1, #ntimes do
  what i want it to do
end

srry i know it seems basic but when i input 10 it only pulses twice instead of 10 times
Ditto8353 #2
Posted 26 October 2012 - 04:35 PM
Remove the # in front of ntimes
# means 'length' or if used on a table 'number of items'

Edit: Actually you will need to replace #ntimes with tonumber(ntimes)
read() gives strings, you need to convert it to a number
NoirVinoCacao #3
Posted 26 October 2012 - 04:37 PM
woops lol
tyvm for the very quick response