Advertisement:

Author Topic: While, counting iterations  (Read 1286 times)

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,274
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
While, counting iterations
« 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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,812
    • Arantor on GitHub
Re: While, counting iterations
« Reply #1 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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,274
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: While, counting iterations
« Reply #2 on: January 11, 2018, 02:37:43 PM »
So echo'ing $count will give me, theoretically, the last count number of 8001?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,812
    • Arantor on GitHub
Re: While, counting iterations
« Reply #3 on: January 11, 2018, 02:38:34 PM »
You could try it and see what happens...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Offline d3vcho(void)

  • Sempiterno
  • Lead Localizer
  • SMF Hero
  • *
  • Posts: 2,668
  • Gender: Male
    • d3vcho on GitHub
Re: While, counting iterations
« Reply #4 on: January 11, 2018, 02:39:05 PM »
If you do $count = 0 after the loop, then it'll output 0.

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 49,455
Re: While, counting iterations
« Reply #5 on: January 11, 2018, 02:47:08 PM »
can you post the code you are using?

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,274
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: While, counting iterations
« Reply #6 on: January 11, 2018, 02:48:01 PM »
Actually, it worked! Thank you.