case/break

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

case/break

Post by phaworth » Sun Oct 25, 2009 11:34 pm

Maybe it's just me, but after using hundreds of switch/case commands, I think I've found one use for have one case statement drop through to the next by omitting the break statement. Conversely, I've been bitten a lot by forgetting to include a break statement.

I don't suppose there's a setting/trick/technique that makes it unnecessary to include break statements....

Pete

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Oct 26, 2009 1:14 am

Hi Pete,

There is no way to make the break unnecessary. Break is very useful though:

Code: Select all

switch theNumber
  case 1
  case 3
  case 5
  case 7
  case 9
    put "The number was odd"
  break
  default
    put "The number was even"
end switch
This is a silly example, but it is provides a good way to illutrate the mechanism.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Mon Oct 26, 2009 1:31 am

Thanks Mark. I understand that it can be useful sometimes and I have made use of it but I'd say 90% or more of the time, I have to use break so to me it would be better if the default was not to drop through and there was another command/keyword that could be used when you do want to drop through to the next case, something like 'continue' perhaps.

Anyway, it's not a big deal, I guess I'm new enough to Rev that I still get annoyed with myself when I forget to use break and weird things hapen!

Pete

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Mon Oct 26, 2009 3:33 am

Pete-

Almost every language that supports a switch statement uses this syntax, so better get used to it. While I agree that I use the break statement a lot more than I drop through (I think 90% is an underestimate), that's just the way it is.

Post Reply