Click here to Skip to main content
15,868,088 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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
Updated 10-Aug-14 5:55am
v2

Inside your 'for' loop:
PERL
if (i % 100 == 0) {
  $nr += 1;
}
 
Share this answer
 
v2
Comments
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??
How about this:
PERL
$nr2++ unless $i%100;

Cheers
Andi
 
Share this answer
 
Comments
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??

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900