Blockland Forums > Modification Help
Why won't this work?
<< < (2/3) > >>
soba:

--- Quote from: Gadgethm on January 23, 2012, 12:22:09 AM ---No, the echo is run on every loop.  The for loop runs for an infinite number of times until %i>=%y then it stops.  So test(%y) would count up to whatever number you put in and echo each time it counts.

--- End quote ---
I see

EDIT: then that loop never ends
Brian Smithers:
Fixed I think. ._.
Nexus:

--- Quote from: Brian Smithers on January 23, 2012, 12:43:05 AM ---Fixed I think. ._.

--- End quote ---
%i++ and echo(%i); you big silly willy

The reason the code in the OP does not work is mainly because it does not loop at all

--- Quote from: I-have-not on January 22, 2012, 11:43:34 PM ---
function count(%y)
{
   %y=0;
   if(%y != 10)
   {
      echo(%y++);
   }
}
--- End quote ---

First of all, the %y=0; would negate the point of having a %y argument
then it tests for if y is equal to ten, since it just got set to zero, this will of course be false.
The it will echo y incremented by one, which is 0+1 = 1
But then it hits the end of the function.  To do this in the format you might be looking for...


--- Code: ---function count(%y)
{
      if(%y < 10)
      {
            echo(%y++);
            count(%y);
      }
}
--- End code ---

Having it call another count will make it loop back and call the function again, causing %y to again be incremented and echoed, which is exactly what you were trying to do.
That way, if you enter count(0); into the console, it should work correctly.

Another method you might have been trying would be

function count(%y)
{
      while(%y<10)
      {
            echo(%y++);
      }
}

which will run all the code inside the while loop until the test (%y<10) is no longer true
Lugnut:
But that last example wouldn't modify the variable
Don't you need a %y++ on its own?
Ipquarx:
Fixed:
--- Code: ---function Count(%end)
{
for(%count = 1; %count <= %end; %count++)
echo(%count);
}
--- End code ---
Navigation
Message Index
Next page
Previous page

Go to full version