13,667,677 members
See more:
```for (\$i=0;\$i<1000;\$i++)
{
my \$nr1= 10 + int(rand(0x150));
my \$nr2 = 10 + 1 after 100 loops
}

So i have this script above in a loop of 1000,
is it possible to add 1 after every 100 loops for my \$nr2 ???
\$nr1 adds every count plus 1.

All help appreciated
Regards,

Dennis```
Posted 10-Aug-14 5:54am
Updated 10-Aug-14 5:55am
v2

Solution 1

Inside your 'for' loop:
```if (i % 100 == 0) {
\$nr += 1;
}```
v2
dennis2704 10-Aug-14 12:47pm

I cannot get it to work it doesnt add a number to it??
what am i doin wrong :(

With just copying the code inside my for loop it does not count??

Solution 2

`\$nr2++ unless \$i%100;`

Cheers
Andi
dennis2704 10-Aug-14 13:13pm

i really appreciate your help and sollution but i can not get it working could you show me with the script from my question how it complete needs to look like.

Sorry for being rettarded but i really can get an increase of the calculation :(
Andreas Gieriet 10-Aug-14 13:41pm

my \$nr2 = 0;
my \$i = 0;
for (\$i = 0; \$i < 100; \$i++)
{
...
\$nr2++ unless \$i % 100;
}
dennis2704 10-Aug-14 14:02pm

yes ok that is working but i want the whol code inside another loop and that loop is set to 1000 so that every 100 loops its adding 1 to the \$nr2.
Andreas Gieriet 11-Aug-14 2:07am

This is something else than asked in the initial question. Show your current code with that nested loop and we can figure out what is wrong.
Andi
dennis2704 11-Aug-14 7:09am

Ok sorry for the miscommunication then from the beginning of my question:
for (\$i=0;\$i<1000;\$i++)
{
my \$nr1 = 10 + int(rand(9));
my \$nr2 = 10 + 1 added each time it hits the 100 loop;
print "\$nr1\n";
print "\$nr2\n";
sleep 5;
}
here is my script basicly what im tryin to get is for the \$nr2 to have an automaticly counting each time the script runs through the 100 loop there is 1 added every 100 times loop
So for my script it should be at 110 at the end of the loop. I hope you understand what i mean. Maybe if its possible could i also use a maximum number for example if i would put the loop on infinite that the maximum of increasement for the sumn starts again from 0 after the 100 is maximum for the counting??
Andreas Gieriet 11-Aug-14 11:36am

If you loop 1000 times and only incremet \$nr2 every 100st loop, then you get 10.
Your question is not clear.
What is clear is that you have no understanding of `my`. As you wrote your code, the \$nr1 and \$nr2 are local to the loop block and therefore get initialized with each iteration and stay the same. You must move out of the loop the `my \$nr1` and `my \$nr2` and delete the `my` inside the loop block. See my initial comment what I mean by this. I wonder why you did not follow this ins your code above and simply copied the original code again... This is not helpful at all.
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 294 ppolymorphe 170 Jochen Arndt 160 Richard MacCutchan 130 F-ES Sitecore 70
 OriginalGriff 4,296 ppolymorphe 1,807 Richard MacCutchan 1,720 Jochen Arndt 1,477 Dave Kreskowiak 853