Studyfin Studyfin ✨ Sign up free

Strings & string manipulation

Grade 6 · Coding · Free lesson

Hi there! Today we will explore how computers handle text using strings, and how we can use nested loops to design cool patterns!

In coding, any text inside quotation marks is called a string. We can join strings together, search through them, or even repeat them using loops.

waves

To solve big coding problems, we use a software design process. First, we break the big problem down into smaller subproblems. Then, we write code to solve each small part.

Big ProblemSubproblem ASubproblem B

We can use nested loops to work with strings. A nested loop is just a loop inside another loop. The outer loop tells us how many rows to make, and the inner loop builds the string for each row.

Nested Loop Output:★ ★ ★(Row 1)★ ★ ★(Row 2)★ ★ ★(Row 3)
✏️ Worked example

Let's design a text-based program to print a grid of smiley faces. We want 3 rows, and each row must have 4 smileys: ':-)'. We will use a software design process to break this down.

  1. Step 1: Identify Subproblem 1. We need to create a single row with 4 smiley face strings joined together.
  2. Step 2: Solve Subproblem 1. We can write an inner loop that repeats the string ':-)' exactly 4 times to make one row.
  3. Step 3: Identify Subproblem 2. We need to repeat this entire row-making process multiple times.
  4. Step 4: Solve Subproblem 2. We wrap our inner loop inside an outer loop that runs 3 times.
  5. Step 5: Combine the solutions. The outer loop runs 3 times. For each run, the inner loop builds and prints the string of 4 smileys. Now we have a perfect grid!
cross
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons