Re: [Flashcoders] Shorhand for if statement without else statement
Heh, that's nothing. I don't have the code available, but I once wrote a ?: statement that was something like 16 deep. Ah, those were the days. :) -Andy On 1/29/07, Steven Sacks | BLITZ <[EMAIL PROTECTED]> wrote: > (foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() : > trace("sorry! no soup for you!"); I feel like I need a shower after that one. ;) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Shorhand for if statement without else statement
Gee ! didn't know it was such a dirty hack ! lol -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks | BLITZ Sent: 29 janvier 2007 13:14 To: Flashcoders mailing list Subject: RE: [Flashcoders] Shorhand for if statement without else statement > (foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() : > trace("sorry! no soup for you!"); I feel like I need a shower after that one. ;) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.410 / Virus Database: 268.17.14/657 - Release Date: 2007-01-29 ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Shorhand for if statement without else statement
> (foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() : > trace("sorry! no soup for you!"); I feel like I need a shower after that one. ;) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
you could take that a bit further : (foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() : trace("sorry! no soup for you!"); Steven Sacks | BLITZ wrote: function foo() { trace("foo"); } function bar() { trace("bar"); } (true) ? foo() : bar(); -- "foo" (false) ? foo() : bar(); -- "bar" Works fine for me. Not the best practice (I would never use it), but just showing what's possible with inline conditionals. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of eka Sent: Friday, January 26, 2007 2:27 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Shorhand for if statement without else statement Hello :) In FDT for example : cond ? methodA() : methodB() failed :) The operator cond ? true : false is used to return a value but isn't really the good solution to launch method i think :) EKA+ :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Shorhand for if statement without else statement
> ( condition ) && ( code ); Hot! I wonder how many of these shortcuts we can come up with that nobody would use unless they were trying to show off to other codemonkeys. :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
You can try: ( condition ) && ( code ); code only executes if condition is true bui I recommend against it, can be confusing sometimes... On 1/26/07, Helmut Granda <[EMAIL PROTECTED]> wrote: does anybody knows if there is any short hand for if statement without the else statement? at the moment I am using object ? true : null; thanks... ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Shorhand for if statement without else statement
function foo() { trace("foo"); } function bar() { trace("bar"); } (true) ? foo() : bar(); -- "foo" (false) ? foo() : bar(); -- "bar" Works fine for me. Not the best practice (I would never use it), but just showing what's possible with inline conditionals. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of eka > Sent: Friday, January 26, 2007 2:27 PM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Shorhand for if statement without > else statement > > Hello :) > > In FDT for example : cond ? methodA() : methodB() failed :) > > The operator cond ? true : false is used to return a value > but isn't really the good solution to launch method i think :) > > EKA+ :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
On 1/26/07, Steven Sacks | BLITZ <[EMAIL PROTECTED]> wrote: > does anybody knows if there is any short hand for if > statement without the else statement? 1. You can remove the braces. I always use: if (true) something(); I like it... ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
Hello :) In FDT for example : cond ? methodA() : methodB() failed :) The operator cond ? true : false is used to return a value but isn't really the good solution to launch method i think :) EKA+ :) 2007/1/26, Steven Sacks | BLITZ <[EMAIL PROTECTED]>: > does anybody knows if there is any short hand for if > statement without the else statement? 1. You can remove the braces. I always use: if (true) something(); But rarely use: if (true) something(); else somethingElse(); because it can get lost visually in code. 2. Inline conditional I use this all the time. val = (boolean) ? trueVal : falseVal; 3. Inline or conditional val = (if true) || (if not true) This one is a little different than the inline conditional. val will be set to what is left of the || if what is left of the || resolves true (i.e. not 0, undefined or null), otherwise it will be set to what's to the right of the ||. You can also use these without setting a variable. // If boolean is true, call funcA, else call funcB. (boolean) ? funcA() : funcB(); // if funcA returns false, run funcB() funcA() || funcB(); HTH, Steven ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Shorhand for if statement without else statement
> does anybody knows if there is any short hand for if > statement without the else statement? 1. You can remove the braces. I always use: if (true) something(); But rarely use: if (true) something(); else somethingElse(); because it can get lost visually in code. 2. Inline conditional I use this all the time. val = (boolean) ? trueVal : falseVal; 3. Inline or conditional val = (if true) || (if not true) This one is a little different than the inline conditional. val will be set to what is left of the || if what is left of the || resolves true (i.e. not 0, undefined or null), otherwise it will be set to what's to the right of the ||. You can also use these without setting a variable. // If boolean is true, call funcA, else call funcB. (boolean) ? funcA() : funcB(); // if funcA returns false, run funcB() funcA() || funcB(); HTH, Steven ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
Hello :) warning with the Boolean( o ) if your object is a number... the Boolean(0) is false but : var n = 0 ; trace(Boolean(n)) ; // false When you test a number the isNaN(n) is better i think :) EKA+ :) 2007/1/26, Helmut Granda <[EMAIL PROTECTED]>: thanks everyone for your comments, yes in reallity I use the regular if {}else{} statement, but I was wondering if there was something similar to when you dont need the else statement, sort of testing on the fly but i think Mark made a good comment on use a return Boolean ( object ); I dont know why i figured that the shorthand was something most people were used to and using already... ...helmut On 1/26/07, John Mark Hawley <[EMAIL PROTECTED]> wrote: > > For that specific example, you can usually turn lines like > > return object ? true : null; > > into > > return Boolean( object ); > > as long as object != 0 and your code doesn't mind getting a false instead > of a null. Most objects, as long as they exist, evaluate to Boolean true. > > Really, though, the ternary operator is confusing enough as is. It tends > to be a lot easier to read and maintain plain old if-statements in the long > run. > > -John Mark Hawley > > > > > > From: "Helmut Granda" <[EMAIL PROTECTED]> > > Date: 2007/01/26 Fri PM 03:01:25 CST > > To: "Flashcoders mailing list" > > Subject: [Flashcoders] Shorhand for if statement without else statement > > > > does anybody knows if there is any short hand for if statement without > the > > else statement? > > > > at the moment I am using > > > > object ? true : null; > > > > thanks... > > ___ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > > > -- > John Mark Hawley > The Nilbog Group > 773.968.4980 (cell) > > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
thanks everyone for your comments, yes in reallity I use the regular if {}else{} statement, but I was wondering if there was something similar to when you dont need the else statement, sort of testing on the fly but i think Mark made a good comment on use a return Boolean ( object ); I dont know why i figured that the shorthand was something most people were used to and using already... ...helmut On 1/26/07, John Mark Hawley <[EMAIL PROTECTED]> wrote: For that specific example, you can usually turn lines like return object ? true : null; into return Boolean( object ); as long as object != 0 and your code doesn't mind getting a false instead of a null. Most objects, as long as they exist, evaluate to Boolean true. Really, though, the ternary operator is confusing enough as is. It tends to be a lot easier to read and maintain plain old if-statements in the long run. -John Mark Hawley > > From: "Helmut Granda" <[EMAIL PROTECTED]> > Date: 2007/01/26 Fri PM 03:01:25 CST > To: "Flashcoders mailing list" > Subject: [Flashcoders] Shorhand for if statement without else statement > > does anybody knows if there is any short hand for if statement without the > else statement? > > at the moment I am using > > object ? true : null; > > thanks... > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- John Mark Hawley The Nilbog Group 773.968.4980 (cell) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
For that specific example, you can usually turn lines like return object ? true : null; into return Boolean( object ); as long as object != 0 and your code doesn't mind getting a false instead of a null. Most objects, as long as they exist, evaluate to Boolean true. Really, though, the ternary operator is confusing enough as is. It tends to be a lot easier to read and maintain plain old if-statements in the long run. -John Mark Hawley > > From: "Helmut Granda" <[EMAIL PROTECTED]> > Date: 2007/01/26 Fri PM 03:01:25 CST > To: "Flashcoders mailing list" > Subject: [Flashcoders] Shorhand for if statement without else statement > > does anybody knows if there is any short hand for if statement without the > else statement? > > at the moment I am using > > object ? true : null; > > thanks... > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- John Mark Hawley The Nilbog Group 773.968.4980 (cell) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
hello :) I don't understand you question ? why you don't use the if keyword ? if ( isNaN(x) ) x = 0 ; you can use the || operator too function write ( txt ) { var message = txt || "empty message" ; trace(message) ; } write("hello") ; // output : hello write() ; // output : empty message if you use the cond?true:false operator to return a true value... you can use directly the condition with the object. if ( myObject ) { trace("myObject exist !!!") ; } myObject is true if is defined and false if is undefined. EKA+ :) 2007/1/26, Helmut Granda <[EMAIL PROTECTED]>: does anybody knows if there is any short hand for if statement without the else statement? at the moment I am using object ? true : null; thanks... ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
if ( condition){ } ? - Original Message - From: "Helmut Granda" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Friday, January 26, 2007 9:01 PM Subject: [Flashcoders] Shorhand for if statement without else statement does anybody knows if there is any short hand for if statement without the else statement? at the moment I am using object ? true : null; thanks... ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Shorhand for if statement without else statement
Usually ?: notation is used specifically for quickly choosing between 2 values (picking between 2 things inline). That's a case where you really have to have an else, otherwise you wouldn't have a value to represent the failure case of the IF part. If you're doing logic that isn't inline in a statement then you really should be using the full syntax (if(...) { ... }). So no, I don't think there is shorthand, as I don't think what you're looking for would be a good construct to have. Then again, I could be wrong. :) -Andy On 1/26/07, Helmut Granda <[EMAIL PROTECTED]> wrote: does anybody knows if there is any short hand for if statement without the else statement? at the moment I am using object ? true : null; thanks... ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com