Studyfin Studyfin ✨ Sign up free

Strings & string manipulation

Grade 9 · Coding · Free lesson

Hey there! Ready to explore how computers handle text? Let's dive into the world of strings and see how we can control them!

In coding, any text inside quotation marks is called a string. We can join strings together, search inside them, or even repeat them using loops to solve real-world problems.

puppet

To solve complex tasks, software designers break problems into smaller subproblems. We can use nested loops—a loop inside another loop—to create repeating patterns of text, like a grid of stars.

Outer Loop (Rows) & Inner Loop (Cols) Nested Repeat

Let us analyze how a nested loop builds a text grid. The outer loop controls which line we are writing, while the inner loop prints each character side-by-side on that same line.

Building a String Grid Step-by-Step: * * * * * * Grid Complete!
✏️ Worked example

Use a software design process to write a program that prints a 3x3 grid of stars (*) using nested loops to solve the subproblem of grid formatting.

  1. 1. Identify the primary goal: We need to output 3 rows of stars, with 3 stars in each row.
  2. 2. Break it into subproblems: Subproblem A is printing a single star. Subproblem B is repeating that star to make a row. Subproblem C is repeating the entire row vertically.
  3. 3. Write the outer loop: Create a loop that runs 3 times to manage the 3 rows.
  4. 4. Write the nested inner loop: Inside the outer loop, create another loop that runs 3 times to print the stars next to each other.
  5. 5. Test the code: Run the program to verify it displays a clean 3x3 grid of text stars.
violin
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons