Coding with Loops Worksheet: Pig to the Barn
Coding with loops for 2nd grade: write the pig's code to the barn with repeat blocks, using at most 7 blocks.
- Size
- US Letter (8.5 × 11 in), fits A4
- 2 pages: the worksheet and its answer key; high-resolution, prints sharp on US Letter and A4
- Level
- Grade 2
- License
- Free for personal & classroom use
About this worksheet
A 7 by 7 grid with the pig, one corn cob to collect and the barn, with three rocks, two logs and two fences in the way. Each block for the pig has an arrow box and a number box: right x3 means three squares to the right. The pig's walk is 16 squares long but fits in 6 blocks, and the sheet gives 7, so kids learn to spot runs of the same arrow. A test line asks them to run the pig's code with a coin. Page 2 shows a shortest code for the pig in blocks. This board is also the level "Pig to the Barn: Loops" in our free online coding game.
Tips for using it
- Write the pig's long code first (one arrow per square), then circle runs of the same arrow and turn each run into one block.
- Ask how many arrows the pig would need without loops: 16!
- Challenge: can your child find another code for the pig that still fits in 7 blocks?
Printing tips
Download the PDF and print at 100% (or “fit to page” on A4). Page 1 is the worksheet and page 2 is the answer key with the answers in red; print just page 1 if you want to keep the answers for checking. Free for personal, family and classroom use.