/ Published in: ActionScript 3

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/*Fumio Nonaka in: Coding|Jump To Comments February 9, 2011 The conditional operator ?: is used to select an alternative value to be assigned. It is basically faster than the if statement.*/ myVariable = (condition) ? valueA : valueB; view plaincopy to clipboardprint? if (condition) { myVariable = valueA; } else { myVariable = valueB; } /*However if the value selected by the conditional operator is to be added with the addition assignment operator +=, its operation will come to be slow.*/ myVariable += (condition) ? valueA : valueB; //Using the assignment operator instead makes it a little faster. myVariable = (condition) ? myVariable + valueA : myVariable + valueB; //But in this case, the if statement is better to use. view plaincopy to clipboardprint? if (condition) { myVariable += valueA; } else { myVariable += valueB; }
URL: http://blog.jactionscripters.com/2011/02/09/when-to-use-the-conditional-operator/
Comments
