Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Biology Forums on January 11, 2018, 01:48:33 PM

Title: While, counting iterations
Post by: Biology Forums on January 11, 2018, 01:48:33 PM
Hi, general coding question

I have a while statement that ends with count++. $count = 0 is defined outside the while statement.

Is there a way to place the last counted iteration as a variable? For example, if there are 8001 iterations, we set $last_count as 8001.

If so, how can I accomplish this?

Thanks
Title: Re: While, counting iterations
Post by: Arantor on January 11, 2018, 02:33:33 PM
It'll be in count... the variable doesn't get unset when you leave the loop, at least in PHP.
Title: Re: While, counting iterations
Post by: Biology Forums on January 11, 2018, 02:37:43 PM
So echo'ing $count will give me, theoretically, the last count number of 8001?
Title: Re: While, counting iterations
Post by: Arantor on January 11, 2018, 02:38:34 PM
You could try it and see what happens...
Title: Re: While, counting iterations
Post by: d3vcho on January 11, 2018, 02:39:05 PM
If you do $count = 0 after the loop, then it'll output 0.
Title: Re: While, counting iterations
Post by: Illori on January 11, 2018, 02:47:08 PM
can you post the code you are using?
Title: Re: While, counting iterations
Post by: Biology Forums on January 11, 2018, 02:48:01 PM
Actually, it worked! Thank you.