start page | rating of books | rating of authors | reviews | copyrights

Book HomeActionScript: The Definitive GuideSearch this book

7.5. Compact Conditional Syntax

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 terseness, ActionScript does not require curly braces when a conditional has only one substatement. A single substatement may quite legitimately be placed directly after an if or an else if statement without any curly braces, like this:

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

Or 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.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.