Skip to content
Exit presentation

Data Handling I: Organizing & Visualizing Data

Every item has a position

Monday's reading is one item in the list. A program cannot say "the Monday one". It must say a number.

Loading lab…

Five boxes: 6, 46, 2, 8, 0. Positions run 0 to 4.
Step 1 of 5
  1. Five boxes: 6, 46, 2, 8, 0. Positions run 0 to 4.
  2. week[0] reads position 0 → 6.
  3. week[2] reads position 2 → 2.
  4. week[4] reads the last position → 0.
  5. week[5] asks past the end. In this editor, the run stops.

The rule

A position is an item's place in the list, counted from 0. Past the end means after the last item. A blank value means nothing is there. A run is one time the program is started.

Every item has a position, starting at 0. The last one sits at .length - 1. In this editor, asking past the end stops the run. The message names both numbers. Other languages may hand back a blank value instead.

Five days are at positions 0 to 4. The count is 5. The last position is 5 − 1 = 4, one less than the count.

Position 5 does not exist in a 5-item list. In this editor, the run stops with this sentence:

You asked for position 5, but the list has 5 items.

Jump to lesson

This track

  1. 0 Start here
  2. 1 One list holds the whole week
  3. 2 Every item has a position
  4. 3 A list the program builds itself
  5. 4 One box outside the loop
  6. 5 Total divided by count
  7. 6 The biggest, without sorting
  8. 7 One count per group
  9. 8 The chart the program drew
  10. 9 The big picture
  11. 10 Track quiz

Other tracks