Skip to Main Content
Essential ActionScript 3.0
book

Essential ActionScript 3.0

by Colin Moock
June 2007
Intermediate to advanced content levelIntermediate to advanced
948 pages
27h 2m
English
O'Reilly Media, Inc.
Content preview from Essential ActionScript 3.0

Chapter 2. Conditionals and Loops

In this chapter, we’ll depart from the general topics of classes and objects. Instead, we’ll focus, on two essential types of statements: conditionals and loops. Conditionals are used to add logic to a program, while loops are used to perform repetitive tasks. Both conditionals and loops are extremely common, and can be found in nearly every ActionScript program. Once we’ve finished with conditionals and loops, we’ll return to classes and objects, and continue developing our virtual zoo program.

This chapter presents all code examples outside the context of a functioning class or program. However, in a real program, conditionals and loops can be used within instance methods, constructor methods, static methods, functions, directly within class bodies or package bodies, and even outside package bodies.

Conditionals

A conditional is a type of statement that executes only when a specified condition is met. Conditionals let a program choose between multiple possible courses of action based on the current circumstances.

ActionScript provides two different conditionals: the if statement and the switch statement. ActionScript also provides a single conditional operator, ?:, which is covered briefly in Chapter 10. For details on the ?: operator, see Adobe’s ActionScript language reference.

The if Statement

The if statement is like a two-pronged fork in the road. It contains two blocks of code and an expression (known as the test expression) that governs which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Essential ActionScript 2.0

Essential ActionScript 2.0

Colin Moock
The ActionScript 3.0 Quick Reference Guide

The ActionScript 3.0 Quick Reference Guide

Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters

Publisher Resources

ISBN: 0596526946Errata