← Back to course
Code Crew G2 / Week 09 / Tuesday
2/6
Week 09 · Read Ten Lines

Tuesday

Loops in long programs
// Read a long program in chunks
⏱ about 15 min
Rocket the inventor holding his engineering tablet

Loops in long programs!

Rocket finds two loops in one program.

Both loops use the count box.

But the count box changes in the middle.

Raven asks, do both loops run the same?

Nova gets her logbook ready.

WARM-UP: CHUNK POWER
  • Read each chunk.
  • Tap the answer.
the program
?
the program
?
A nine line program with two loops that use the count box

Two loops, one count box

Repeat count times peeks in the count box.

The box tells the loop how many rounds.

set count to 3
set height to 1
repeat count times:
change height by 2
stop
say height
change count by 1
repeat count times:
flash lights
A logbook of the first loop: height goes 1, 3, 5, 7

Nova tracks the loop

Count holds 3, so three rounds.

Height goes 1, 3, 5, 7.

Each round adds 2.

LOOP BY LOOP
  • Track the boxes through each loop.
  • Tap the answer.
lines 1 to 6
?
count holds 3
lines 7 to 9
?
the program
?

Build a loop that counts with a box.

Height starts at 1.

Nova must say 5.

MAKE NOVA SAY 5
  • Fill both boxes first.
  • Loop, then Nova says 5.
1line 1
2line 2
3line 3
4line 4
5line 5
6line 6
Raven the explorer with her wrist computer

What do you notice?

Both loops say repeat count times.

But count changed in between.

So the loops ran different rounds!

set count to 3
set height to 1
repeat count times:
change height by 2
stop
say height
change count by 1
repeat count times:
flash lights
afterthe logbook saystrue?
line 2height is 1?
line 6height is 7?
line 7count is 3?
line 9count is 4?

Word Spot: upon, us, river

Here are new sight words.

Look at each word. Say it. Spell it.

Upon: U-P-O-N.

Us: U-S.

River: R-I-V-E-R.

FIND THE WORD
  • Listen to the word.
  • Tap it.
Listen and find
?
Listen and find
?
Listen and find
?
Listen and find
?
FILL THE GAP
  • Listen to the sentence.
  • Tap the missing word.
Which word fits?
?
Which word fits?
?

Loops? You got this!

A box can count a loop.

The loop peeks when it starts.

Track every round in a logbook.

See you tomorrow, Crew!

← Monday