Hello Guest

avoiding a long serie of similar lines

  • 4 Replies
  • 850 Views
*

parisd

  • **
  • 20
  • +0/-0
    • View Profile
avoiding a long serie of similar lines
« on: November 26, 2020, 04:28:48 pm »
I am trying to escape from writing by hand a long number of similar lines like
Bet1 = 0;
Bet2 = 0;
...
Bet100 = 0;

using the equivalent of

for i=1 to 100
Beti = 0
next

or

for i=1 to 100
Bet(i) = 0
next

any proposal?

Thanks

*

Seuntjie

  • *****
  • 593
  • +17/-3
    • View Profile
Re: avoiding a long serie of similar lines
« Reply #1 on: November 26, 2020, 05:05:07 pm »
What are yo trying to achieve?

*

parisd

  • **
  • 20
  • +0/-0
    • View Profile
Re: avoiding a long serie of similar lines
« Reply #2 on: November 26, 2020, 07:33:27 pm »
What are yo trying to achieve?

too long to explain here but trying to avoid to write by hand too many line of code, for example for the following

B13  = B12
B12  = B11
B11  = B10
B10  = B9
B9   = B8
B8   = B7
B7   = B6
B6   = B5
B5   = B4
B4   = B3
B3   = B2
B2   = B1

*

Seuntjie

  • *****
  • 593
  • +17/-3
    • View Profile
Re: avoiding a long serie of similar lines
« Reply #3 on: November 27, 2020, 07:21:06 am »
It's impossible to give you a solution without knowing what you're trying to do with your script. It's quite possible that a simple sum, multiplication and/or modulu can solve your problem.

The best answer I can give now, without context, is to look into arrays and for loops.
https://www.lua.org/pil/11.1.html

*

parisd

  • **
  • 20
  • +0/-0
    • View Profile
Re: avoiding a long serie of similar lines
« Reply #4 on: November 29, 2020, 02:55:11 pm »
thanks you for the link, I did not know it was called array.

I tried the simplest one

b = {}
    for i = 1,200 do
        b[ i ] = 1
    end
  and I receives the following error in the console : Attempt to compare with nil ??

Tks
« Last Edit: November 29, 2020, 04:01:53 pm by parisd »