7.5 Compact Conditional Syntax

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 7.  Conditionals

Throughout this book we use statement blocks (statements surrounded by curly braces) with all conditional statements, even if a block contains only one statement:

if (x =  = y) {   trace("x and y are equal"); }

For the sake of brevity, ActionScript does not require curly braces when a conditional has only one substatement. A single substatement can, quite legitimately, be placed directly after an if or else if statement without any curly braces, like this:

if (x =  = y) trace ("x and y are equal");

or even on the next line, like this:

if (x =  = y)   trace ("x and y are equal");

For some programmers, this style can be a little slower to read and slightly more error-prone, though it undeniably saves room in source code.

     



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net