Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 2 of 8

One name for a group

Show on a big screen

7 min

Text size

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…

Try the lab to finish this lesson.