Blockland Forums > Modification Help
Is there a way to multiply together the output of a loop?
(1/4) > >>
Jetpuff:
Loop: for(%a=1; %a<10; %a++)
if echoed: 1 2 3 4 5 6 7 8 9
Question: How do I multiply the output together?

(Yes it probably is a stupid question, I just started scripting)
Bauklotz:
Is it something like this you want?

--- Code: ---for(%i=1;%i<=10;%i++)
{
    echo(%i);
    %num = %num * %i;
}
echo(%num);

--- End code ---
Echoes the following:
1
2
3
4
5
6
7
8
9
10
3628800

Or did you mean this:

--- Code: ---for(%i=1;%i<=10;%i++)
{
    echo(%i);
    %num = %num + %i;
}
echo(%num);

--- End code ---
1
2
3
4
5
6
7
8
9
10
55
Jetpuff:

--- Quote from: Jetpuff on November 20, 2010, 01:42:15 AM --- multiply

--- End quote ---

Thanks a bunch ;)
Jetpuff:

for(%a=1; %a<10; %a++)
{
echo(%a);
%answer=%answer*%a;
}
echo(%answer);

I end up with zero. Why is that? Does %answer need a value?
MegaScientifical:

--- Quote from: Jetpuff on November 20, 2010, 02:18:03 AM ---I end up with zero. Why is that? Does %answer need a value?

--- End quote ---

Yes. It's like trying to multiply by nothing (zero).
Navigation
Message Index
Next page

Go to full version