0

This is just by curiusity, how can i count the number of times a given cycle works. for instance:

    for($x=1; $x <=5; $x++) {

    for ($i=1; $i <= 5; $i++) {

        for($y=1; $y<=5; $y++) {

            for($j=1; $j<=5; $j++) {

                for($z=1; $z<=5; $z++) {

                    echo($x." - ".$i." - ".$y." - ".$j." - ".$z."<br>");

                }
            }
        }
    }
}

And the display is something like this:

1 - 1 - 1 - 1 - 1
1 - 1 - 1 - 1 - 2
1 - 1 - 1 - 1 - 3
1 - 1 - 1 - 1 - 4
1 - 1 - 1 - 1 - 5
1 - 1 - 1 - 2 - 1
...

All works fine, and i know by math the $z cycle is changed 3125 times, but i'm sure there is a way to count this. Any tips? Thanks

1 Answer 1

4
$count = 0;
for($x=1; $x <=5; $x++) {
    for ($i=1; $i <= 5; $i++) {
        for($y=1; $y<=5; $y++) {
            for($j=1; $j<=5; $j++) {
                for($z=1; $z<=5; $z++) {
                    echo($x." - ".$i." - ".$y." - ".$j." - ".$z."<br>");
                    $count++;
                }
            }
        }
    }
}
echo $count;
Sign up to request clarification or add additional context in comments.

1 Comment

Ofc, thanks very much, i feel stupid now... i will acept your anwser in 9 mins. cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.