Hi there! I’m Jerome Holman, and I work with the Windows devices team at Microsoft. We create cool products like tablets, phones, and the Hololens to make technology exciting for everyone.
Computers might not be the fastest at everything, but they are incredibly good at doing repetitive tasks quickly. For example, back in 2014, the fastest computer could do 33 quadrillion calculations every second! While humans are better at creative tasks like composing music, computers shine when it comes to repetitive tasks that can be automated.
In programming, we use loops to handle repetitive tasks. Different programming languages have various types of loops, such as For-Loops, While-Loops, Do-While-Loops, For-Each-Loops, and Repeat-Loops. Despite their different names, they all help us repeat a set of instructions multiple times.
The term “iteration” is often used to describe the process of looping, meaning to repeat something. In programming, we use loops to repeat a process until a certain condition is met or for a specific number of times.
Let’s explore how to use a For-Loop in JavaScript. You can find For-Loops in the control section of your programming toolbox. When you drag it out, it appears as a block. A For-Loop in JavaScript is a type of loop that counts from zero up to a specified number.
Although a For-Loop might seem complex at first, it’s a powerful tool for both simple and advanced tasks. You can place any commands inside the For-Loop block, and these commands will execute repeatedly for the number of times you specify.
Let’s try something fun! Instead of running a piece of code four times, let’s loop it 200 times and see what happens. This will show you the power of loops and how they can handle large tasks efficiently.
Remember, your code will still execute in order, from top to bottom. You can set up conditions before the loop and continue with other commands after the loop finishes. For example, if you want to move a turtle before drawing a shape, you can use a moveTo command before the loop. If you want to mark the turtle’s final position, you can add a command to draw a red dot after the loop.
In many projects, you’ll use loops to solve problems efficiently. You might create a function for a small task and use a loop to call that function multiple times. For instance, if you want to draw a series of squares, each slightly rotated, you can create a function to draw a square and use a loop to repeat it with different angles.
Using loops makes your code clearer and easier to read. It shows the intent to repeat a task multiple times, leveraging the computer’s speed to handle tasks that would be too tedious for humans.
There’s still a lot to learn about loops, but the basic idea is simple: loops repeat commands as many times as needed. Now that you know how to use a simple loop, you can start using your computer’s power and speed to create amazing programs.
Grab a piece of paper and a pencil. Write down a simple task, like drawing a star. Now, repeat this task five times on the same sheet. Notice how repetitive tasks can be simplified using loops in programming. This activity will help you understand the concept of iteration by mimicking a loop manually.
Use a basic JavaScript editor to create a simple animation. Write a For-Loop to move a shape across the screen. Experiment by changing the loop’s parameters to see how it affects the animation speed and distance. This will give you hands-on experience with For-Loops and how they control repetitive tasks in programming.
Think about a daily routine, like brushing your teeth or tying your shoes. Break it down into steps and identify any repetitive actions. Discuss with your classmates how loops could be used to automate these tasks if they were part of a computer program. This will help you connect programming concepts to real-world scenarios.
Use a programming tool like Scratch to create a piece of digital art using loops. Design a pattern that repeats multiple times to form a larger image. Share your artwork with the class and explain how loops helped you create it efficiently. This activity will enhance your creativity while reinforcing loop concepts.
Work with a partner to solve a series of loop-related bugs in a sample code. Identify errors in loop logic and fix them to achieve the desired output. This challenge will improve your problem-solving skills and deepen your understanding of how loops function in programming.
Here’s a sanitized version of the provided YouTube transcript:
—
My name is Jerome Holman, and I work in the Windows devices group at Microsoft. It’s a team focused on creating innovative products like tablets, phones, and Hololens, aimed at exciting and delighting customers.
Computers may not be infinitely fast, but they excel at many tasks compared to humans. In 2014, the fastest computer in the world was capable of an impressive 33 quadrillion calculations per second. While humans generally outperform computers in creative tasks like composing music, computers are far superior in highly repetitive tasks that can be automated.
Programming languages offer various ways to define and control repetitive behavior, commonly referred to as loops. These loops have different names across languages, such as For-Loop, While-Loop, Do-While-Loop, For-Each-Loop, and Repeat-Loop. Despite their differences, they all serve the same purpose: to execute a set of instructions repeatedly.
The term “iteration” is a general term for looping, meaning “repeat.” It typically refers to the repetition of a process or procedure, making it a suitable term in programming. Often, we have algorithms that require repetition a specific number of times or until a certain condition is met.
In this session, we will demonstrate how to use a looping structure called a For-Loop in JavaScript. You can find For-Loops in the control section of the toolbox. When you drag it out, it appears as a block. A For-Loop in JavaScript is a type of counter loop that counts from zero to the specified number.
You might wonder why this simple For-Loop appears complex. Unlike some languages, JavaScript does not provide a straightforward repeat loop structure. However, the For-Loop is a powerful and versatile tool for both simple and advanced tasks, and we will keep it simple for now.
Let’s experiment a bit. You can place any commands inside the For-Loop block, and these commands will execute repeatedly for the number of times you specify. When you run the loop, the app lab highlights each line as it executes. The For-Loop block highlights after each iteration because it checks its counter to determine whether to continue executing the commands inside the loop.
While this may not seem thrilling, it’s important to utilize the computing power that looping provides. Instead of looping a piece of code four times, let’s try looping it 200 times and observe the results.
One important aspect of loops is that your code will still execute sequentially, from top to bottom. You can place lines of code before the loop to set up any necessary conditions. Similarly, after the loop finishes executing, it will continue from the line immediately following it. For instance, if you want to move the turtle before drawing a figure, you could use a moveTo command before the loop. If you want to draw a red dot to mark the turtle’s final position, you could add lines after the loop.
You will apply this top-down design in many of your projects. These problem-solving techniques will help you determine where loops fit into your code. You might also want to create a function for a small part of your program and then use a loop to call that function.
For example, if you want to draw a series of squares, each slightly rotated, you would typically create a function to draw a square and call it multiple times, adjusting the angle each time. This approach can lead to repetitive code. Instead, we can simplify our code by using a loop. Since we already have a working function that performs the drawing task once, we can easily incorporate the function call into a loop to execute it multiple times.
Clarity and readability are crucial in programming. With the loop, our code becomes much more readable, clearly indicating the intent to draw a square multiple times. Loops are a powerful programming construct that leverage the speed advantage of computers over humans. By repeating commands as needed, loops enable us to tackle problems at a scale that would be unmanageable without computers.
There is still much to learn about loops, but the concept is straightforward: loops repeat commands as many times as necessary. Now you know how to use a simple loop, allowing you to harness your computer’s power and speed in your programs.
—
This version maintains the core content while removing any informal language and ensuring clarity.
Loops – A sequence of instructions that is continually repeated until a certain condition is reached. – In coding class, we learned how to use loops to make the computer repeat tasks automatically.
Programming – The process of designing and building an executable computer program to accomplish a specific task. – Sarah enjoys programming because she can create games and solve problems using code.
Computers – Electronic devices that can store, retrieve, and process data to perform various tasks. – Computers have become essential tools for students to research and complete their homework.
Tasks – Specific jobs or operations that a computer program is designed to perform. – The software was updated to handle multiple tasks more efficiently.
Code – A set of instructions written in a programming language that a computer can execute. – When you write code, you are telling the computer exactly what to do step by step.
JavaScript – A programming language commonly used to create interactive effects within web browsers. – We used JavaScript to add a dynamic slideshow to our website project.
Function – A block of organized, reusable code that performs a single, specific task. – The function we wrote calculates the total score of the game automatically.
Repeat – To execute the same set of instructions multiple times in a program. – The program will repeat the animation until the user decides to stop it.
Control – Mechanisms in programming that manage the flow of execution of a program. – Using control structures like if-statements, we can make decisions in our code.
Project – A planned set of coding activities aimed at achieving a particular goal, often involving multiple tasks and resources. – For our final project, we are developing a simple app that helps track homework assignments.