Hi there! I am Studyfin, your friendly coding buddy. Today, we will learn how computers use text!
In coding, we call any text a string. A string is just a line of letters, numbers, or symbols. We wrap them in quotation marks so the computer knows it is text.
We can join two strings together to make a new, longer string. This is called concatenation. It is like gluing two words together with a plus sign!
Sometimes we want to repeat a message. We can use a nested loop to print our strings inside another loop. We do this to solve different parts of a big task step by step.
✏️ Worked example
We want to write a program that prints a pattern for a game. It needs to print two rows. Each row must print the word 'Go' three times in a row.
- First, we plan our program using a software design process. We break the big goal into smaller tasks.
- Our first subproblem is to print the word 'Go' three times. We can do this by adding strings together inside an inner loop.
- Our second subproblem is to repeat that whole row two times. We will use an outer loop for this.
- We put the inner loop inside the outer loop. This is called a nested loop.
- When we run the code, the program prints 'GoGoGo' on the first line, and 'GoGoGo' on the second line!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?