I want to put as many for
cycles in themselfs depending of value in a variable.
For example, if the variable @var = 1
, I need to perform:
for letter1 in @range
do something
end
If the variable @var = 2
:
for letter1 in @range
for letter2 in @range
do something
end
end
If the variable @var = 3
for letter1 in @range
for letter2 in @range
for letter3 in @range
do something
end
end
end
Is there a smarter/less code way than this code below? I don't wanna repeat myself all over again.
if @var == 1
for letter2 in @range
do something
end
elsif @var == 2
for letter1 in @range
for letter2 in @range
do something
end
end
elsif @var == 3
for letter1 in @range
for letter2 in @range
for letter3 in @range
do something
end
end
end
end
That do something
part is always the same in each case. The difference is only how much cycles it is in.