Poll

Use brackets in your REPEAT/UNTIL loops or are you bracketless?

Brackets { }
No brackets
I do both and never really thought much of it
I don't know what a loop is

Author Topic: REPEAT/UNTIL Loops - Do you use brackets or none?  (Read 9302 times)

0 Members and 1 Guest are viewing this topic.

Offline 12TimesOverTopic starter

  • 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
REPEAT/UNTIL Loops - Do you use brackets or none?
« on: January 26, 2010, 12:36:52 PM »
0
I go back and forth for no apparent reason other than my mood I guess. I'm going to pick one and stick with it. What do you do?
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 Superslayer

  • Elite
  • *
  • *
  • Posts: 1006
  • Activity:
    0%
  • Reputation Power: 14
  • Superslayer barely matters.Superslayer barely matters.
  • Gender: Male
  • Well what do you drink? Not tea.
  • Respect: +43
  • Referrals: 0
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #1 on: January 26, 2010, 12:39:51 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

Scrripty

  • Guest
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #2 on: January 26, 2010, 12:48:09 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

I do depending on how many lines also.  But one interesting thing to note:  It's a good idea to use wait 1's in your repeat loops for non or only semi time critical functions.  According to Roadkill it produces less wear and tear on your cpu and is a little more stable.

The difference between this:

Code: [Select]
repeat
until #charghost = yes

and

Code: [Select]
repeat
  wait 1
until #charghost = yes

is about 20000 iterations... :)  So you can see how much of a saving on your processor that is... and you're still doing a TON of iterations using that wait 1.  Be fun to write a little bit of code to test just how many iterations per second those do on a few computers to get an idea of the kind of issues it would cause based on processor speed.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #3 on: January 26, 2010, 01:23:11 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #4 on: January 26, 2010, 01:27:02 PM »
0
I use them, always.

It helps me visually see what all is included in the repeat. Everything is indented nicely ;)
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Scrripty

  • Guest
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #5 on: January 26, 2010, 01:34:37 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #6 on: January 26, 2010, 01:36:33 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.

I know thats what i said.. but i also said EUO glitches sometimes with one line and no brackets (for loops)
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

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: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #7 on: January 26, 2010, 01:58:55 PM »
0
Kinda silly to use them with a repeat/until construct.  Brackets are "implied" with the repeat/until.  So it's like having brackets for your brackets.  Redundant for sure!
Please read the ScriptUO site RULES
Come play RIFT with me!

Scrripty

  • Guest
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #8 on: January 26, 2010, 02:06:33 PM »
0
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.

I know thats what i said.. but i also said EUO glitches sometimes with one line and no brackets (for loops)


Cut me some slack.  I'm sick. :)

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #9 on: January 26, 2010, 02:09:33 PM »
0
lol ;)
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #10 on: January 26, 2010, 02:51:33 PM »
0
if you do

for #findindex 1 #findcnt
gosub Whatever

It starts you off on #findindex = 2 thats the glitch. I've seen it happen a dozen times. if you don't have brackets it will skip over your first number.


I always use brackets on my repeat untils unless its only 1 line of code inbetween. I always thought it was mandatory. I wonder if thats why they use endif in vb..... to save lines?
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline Superslayer

  • Elite
  • *
  • *
  • Posts: 1006
  • Activity:
    0%
  • Reputation Power: 14
  • Superslayer barely matters.Superslayer barely matters.
  • Gender: Male
  • Well what do you drink? Not tea.
  • Respect: +43
  • Referrals: 0
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #11 on: January 26, 2010, 03:40:46 PM »
0
if you do

for #findindex 1 #findcnt
gosub Whatever

It starts you off on #findindex = 2 thats the glitch. I've seen it happen a dozen times. if you don't have brackets it will skip over your first number.


I always use brackets on my repeat untils unless its only 1 line of code inbetween. I always thought it was mandatory. I wonder if thats why they use endif in vb..... to save lines?

I love the endif functions. I've used them in javascript before and wish they'd be employed in euo.

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #12 on: February 07, 2010, 03:45:09 AM »
0
HAH! I KNEW IT!!

I knew there was some reason I ALWAYS use {} after a "repeat" AND "if". And now, you all will too....

if #finddist > 4
;  move #findx #findy 2
  event pathFind #findx #findy #findz

By allowing the "if" statement to execute the next line, it actually recognizes the ; (rem) statement as the condition. It would ALWAYS perform the "event pathFind".

if #finddist > 4
  {
;  move #findx #findy 2
  event pathFind #findx #findy #findz
  }

Changed to that, using the brackets, it works perfectly and ONLY executes the "event pathFind" if greater then 2 tiles away.

I didn't test it with Repeat, but I'd assume the same situation.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Khameleon

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2574
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +238
  • Referrals: 0
    • View Profile
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #13 on: February 07, 2010, 04:00:17 AM »
0
the if statment without brackets will always read the 2nd line weather the 1st line is commented out or blank....

not sure if alot of ppl realize this but you can also tell the if statement how many lines are in the statement.  if You ask me its very tough to keep track of this exspecially if you edit a script.

Code: [Select]
start:
if #Findking = -1 2
   ignoreitem #Findid
   goto start
does the same thing as
Code: [Select]
start:
if #FindKind = -1
   {
   ignoreitem #findId
   Goto Start
   }

but this will only read the next line if the statement is true.
Code: [Select]
Start:
If #FindKind = -1
Ignoreitem #findID ; if the statement is true this line will be read
goto Start ; this line will always be read since its not bracketed.

Scrripty

  • Guest
Re: REPEAT/UNTIL Loops - Do you use brackets or none?
« Reply #14 on: February 07, 2010, 01:28:46 PM »
0
Yea the whole designating how many lines are behind an if thing is nice, I learned about it a while back, but it's not really necessary in EUO, the only times I could ever see using it are in a REALLY time constrained situation where you need to do something in as few lines as possible.  Say like scanning TONS and TONS of data where every line makes a difference in speed?  I have tried it, and it saves 2 lines of code in every if statement, but there's really not many real situations where it's necessary.  Easier to read imo with brackets also. :)

Tags: