Poll

Which is better to use?

While
1 (20%)
Repeat / Until
4 (80%)

Total Members Voted: 5

Author Topic: While or Repeat/Until  (Read 6201 times)

0 Members and 1 Guest are viewing this topic.

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1625
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • Insane UO
Re: While or Repeat/Until
« Reply #15 on: April 16, 2009, 09:40:17 AM »
0
Here's the precise use of while and repeat until loops (same as while and "do while" loops in C or C++):

While loops check a condition FIRST, then execute code if the condition is met.

Repeat/Until loops execute code at least once, THEN check the condition.


So....in the case where you want to "wait" until a creature is killed, the appropriate use would be:
Code: [Select]
repeat
  finditem !target
until #findCnt = 0

This is because you want to execute the code THEN check the result. Like has been mentioned before, with the while loop, you have to "seed" the value by adding an extra finditem immediately before the while loop (thereby losing any line-saving advantage)

As for the brackets, it is proper coding format to use brackets for anything that is multi-line. Repeat/Until loops have implicit brackets, however, when NESTING repeat/until loops with no brackets, you can have undesired results (if you are an idiot and don't know how to use them, LOL)!!!!
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: While or Repeat/Until
« Reply #16 on: April 16, 2009, 09:49:22 AM »
0
Thanks for that concise explanation!
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: While or Repeat/Until
« Reply #17 on: April 16, 2009, 10:33:05 AM »
0
Hmm, I thought I already said that. I must not have been as precise :p

XII
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: While or Repeat/Until
« Reply #18 on: April 16, 2009, 10:48:14 AM »
0
Precise-er-er?
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: