| Blockland Forums > Modification Help |
| Why won't this work? |
| (1/3) > >> |
| I-have-not:
I'm trying to make it echo 1 2 3 4 5 6 7 8 9 10 by using this script in console : function count(%y){ %y=0; if(%y != 10){echo(%y++);}} but for some reason it only echoes: 1 why won't this script work? Any help please? |
| Brian Smithers:
function test(%y) { for(%i=0;%i<%y;%i++) echo(%y); } Fixed :) for(statement used on start; statement check for end; statement used when finished) { your work } :) |
| I-have-not:
--- Quote from: Brian Smithers on January 22, 2012, 11:55:43 PM ---function test(%y) { for(%i=0;%i<%y;%y++) echo(%y); } Written on my iPad c: --- End quote --- This makes no sense to me? line 2 makes no sense. I don't understand, it could be easier if you explained. |
| soba:
--- Quote from: Brian Smithers on January 22, 2012, 11:55:43 PM ---function test(%y) { for(%i=0;%i<%y;%y++) echo(%y); } Written on my iPad c: --- End quote --- Wouldn't this only echo once? resulting in you needing to enter it 10 times to get the desired result? and @OP, you don't actually alter the value, you echo it with a +1, and since the value is 0, it will always echo 1 |
| Gadgethm:
--- Quote from: soba on January 23, 2012, 12:18:29 AM ---Wouldn't this only echo once? resulting in you needing to enter it 10 times to get the desired result? --- End quote --- 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. |
| Navigation |
| Message Index |
| Next page |