Jump to content

[SOLVED] Filtering a pattern of numbers in a loop?


Freeform

Recommended Posts

Ok, so in php, I have a basic loop, $f counts to 1000.  What I am trying to accomplish is an event that is going to take place within the while loop.  I would like to skip every fourth count and have that variable = "";.  I do not want to accomplish this by using an array simply because it's a sequential pattern that repeats throughout the numbers I need.  I have no idea if it's possible, and any help is much appreciated.

 

- Ben

 

 

Its a little hard to tell what your after exactly... Something like...

 

<?php

    for($i = 1;$i <= 1000; $i++) {
        if (($i % 4) != 0) {
            echo $i."\n";

        }
    }


?>

 

perhaps?

 

ahh beautiful, yes exactly.  What does the % function do?  Is it an exemption for ever 4th character, or rather a division/calculating function?  Point being that this algorithm is going to go into very large numbers.  It's a prime sieve I am working on.   ;D

 

- & thank you also.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.