Hi all ,
I have loop and I would like to calculate an expression only when the index is even
for($j=0; $j<=100; $j++){
if ( ){
do the expression
}
}
i.e how do I tell perl to do the if statement when $j is an even number?
Thanks
Hi all ,
I have loop and I would like to calculate an expression only when the index is even
for($j=0; $j<=100; $j++){
if ( ){
do the expression
}
}
i.e how do I tell perl to do the if statement when $j is an even number?
Thanks
for($j=0; $j<=100; $j++){
<do the expression> unless($j%2);
}
If you are doing some mathematical operation with the expression i think you want to re-check whether loop should start from 0.
katharnakh.
If you want to process the even number indices of an array:
for (my $i = 0; $i <= $#array; $i+=2) {
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.