Skip to content
Exit presentation

Programming with Blocks III: Bridge to Text

One name for a group

The same three blocks appear again and again. Give them one name. Write the group once, with its name. That is defining it.

One group: dot, dot, new line.
Step 1 of 4
  1. One group: dot, dot, new line.
  2. Four copies written out: 12 lines.
  3. Named: 4 lines to define it, then 4 calls: 8 lines.
  4. The blocks that run are the same: 12.

The rule

A named group of blocks is a function. Using its name is a call.

Naming a group does not change which blocks run. It changes how many lines you read.

The group of 3 blocks, used again and again
CopiesWritten outNamedBlocks run
1353
2666
3979
6181018

Here we count only the blocks that run. A call only points to the group. A call line is not counted as a block.

Naming costs 4 lines to define the group. That is 1 line for the name and 3 for the blocks. Each call adds 1 line. For 3 copies, naming takes 4 + 3 = 7 lines. Writing it out takes 3 × 3 = 9 lines. At 2 copies, both need 6 lines. From 3 copies, naming needs fewer lines.

Change the copies. Compare the lines.

Loading lab…

Jump to lesson

This track

  1. 0 Start here
  2. 1 Blocks written as words
  3. 2 One name for a group
  4. 3 A named group that takes a number
  5. 4 Working out what written steps do
  6. 5 Text must be exact
  7. 6 The big picture
  8. 7 Track quiz

Other tracks