Advertisement:

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

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,335
    • 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: 69,317
    • StoryBB/StoryBB 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,335
    • 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: 69,317
    • StoryBB/StoryBB on GitHub
Re: While, counting iterations
« Reply #3 on: January 11, 2018, 02:38:34 PM »
You could try it and see what happens...
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Online d3vcho(void)

  • Sempiterno
  • Lead Localizer
  • SMF Hero
  • *
  • Posts: 2,919
  • Gender: Male
    • frandominguez03 on GitHub
    • @_d3vcho on Twitter
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.
"Demons are like obedient dogs; they come when they're called"

d3vcho(void)

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 49,851
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,335
    • 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.