WebReference.com logo
tip archive  •   about  •   sitemap  •   contact  •   jobs  •   write for us  •   subscribe


[previous] [next]

Primitive Data Types, Arrays, Loops, and Conditions: Part 3 [con't]

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Arrays of arrays

An array can contain any type of values, including other arrays.

Let's see an example where you have an array of two elements, each of them being an array.

The first element of the array is a[0] and it is an array itself.

To access an element in the nested array, you refer to the element index in another set of square brackets.

Note also that you can use the array notation to access individual characters inside a string.

There are more ways to have fun with arrays (and we'll get to that in Chapter 4), but let's stop here for now, remembering that:

Conditions and Loops

Conditions provide a simple but powerful way to control the flow of execution through a piece of code. Loops allow you to perform repeating operations with less code. Let's take a look at:

Code Blocks

Let's start by clarifying what a block of code is, as blocks are used extensively when constructing conditions and loops.

A block of code consists of zero or more expressions enclosed in curly brackets.

You can nest blocks within each other indefinitely:

Best Practice Tips

Ready to jump into loops and ifs? Note that the examples in the following sections require you to switch to the multi-line Firebug console.

if Conditions

Here's a simple example of an if condition:

The parts of the if condition are:

The condition (the part in parentheses) always returns a boolean value and may contain:

There can also be an optional else part of the if condition. The else statement is followed by a block of code to be executed if the condition was evaluated to false.

In between the if and the else, there can also be an unlimited number of else if conditions. Here's an example:

You can also nest conditions by putting new conditions within any of the blocks.


[previous] [next]

Recent Articles

WebReference.com site name
Rolling Out Your Own HTML Application Version Control
HTML 5: Client-side Storage
Working with Ajax Server Extensions
internet.com site name
Wi-Fi Product Watch, November 2009
Chip Market Recovering From '08 Collapse
Low-Cost Tools to Kickstart Your New Business


internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs