It is currently May 18th, 2022, 3:28 am

## [Solved]Repeat Loop? (Lua)

Discuss the use of Lua in Script measures. revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

### [Solved]Repeat Loop? (Lua)

So far I have:

Code: Select all

``````   repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until (tonumber(Check[i]) >= 10 or tonumber(Check[i]) < 0) or Check[i] == 'x'``````
But for some reason, these few lines create an error. What am I doing wrong?

Here's the rest of the (important) code:

Code: Select all

``````function Initialize()
Equation = SKIN:GetVariable('Equation')
Solveable = 1
Coefficients = {}
Numbers = {}
Check = {}
k=0
for i=1,#Equation do
Coefficients[i] = '0'
end
for i=1,#Equation do
Coefficients[i] = string.sub(Equation, i, i)
end
for i=1,#Equation do
Numbers[i] = ''
end
for i=1,#Equation do
Check[i] = '0'
end
i=1
repeat
Check[i] = Coefficients[i]
Numbers = Numbers..Check[i]
i = i+1
until (tonumber(Check[i]) >= 10 or tonumber(Check[i]) < 0) or Check[i] == 'x'``````
Any help is much appreciated!
Last edited by revolt4peace on February 17th, 2015, 7:16 pm, edited 1 time in total.
Click Me! - My Algebra Solver for Rainmeter! revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

### Re: Repeat Loop? (Lua)

I have figured out that it has something to do with the last line:

Code: Select all

``until tonumber(Check[i]) >= 10 or tonumber(Check[i]) < 0 or Check[i] == 'x'``
and that it may have something to do with the possibility that Check may not be a string (or is it char?) that I thought it was. Possibly. Another possibility is that I'm doing something else wrong in that line...

Click Me! - My Algebra Solver for Rainmeter! balala
Rainmeter Sage
Posts: 14207
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Repeat Loop? (Lua)

In your original repeat .. until cycle, on the until check, Check is always equal with '0', because when you have certain value for i (and Check gets the value of Coefficients) after the assignement of Check and Numbers, the value of i increments, so the until condition is checked with this new value. So, on the until line Check is always equal with '0', the condition won't never be true and that's why the cycle never ends.
To avoid it, I'd move the assigning of Check array outside of the repeat .. until cycle:

Code: Select all

``````for i=1,#Equation do
Check[i] = Coefficients[i]
end``````