LSP- Loops to Solve Problems in Programming Overview
Using Loops to Solve Problems in Programming
Repetition is one of the basic control structures in programming. It is used to repeat a block of code or some action over and over again until some condition occurs to stop it. It is also called iteration, a loop, or a repeat. Loops simplify and reduce the overall number of lines of code needed to perform a specific task. Most games have a game loop that runs continuously during gameplay. Each program has its own type of game loop specific to the program. It tracks the passage of time to control the rate of gameplay. The draw () function in Processing is similar to a game loop because it is continually called while the program is running. However, there are times when we need to use control structures to repeat blocks of code. The basic repetition control structures we will look at are for statements and while statements.
Another type of repetition is recursion. Recursion is different from a repetition structure. It is a function created that calls itself. Some problems are easier to solve through recursion than repetition and require less code. Both of these types of constructs are extremely powerful techniques that simplify the way problems can be solved. In this module, you will understand and use each of the different types of loop structures and recursion to create a program that will solve a problem.
Essential Questions
- Why is repetition one of the basic structures of programming?
- What are the different types of loop structures?
- What is an infinite loop?
- What is the difference between repetition and recursion?
- How are repetition and recursion used in programming to solve a problem?
Key Terms
Repetition - a programming structure that repeats lines of code over and over.
Recursion - when a method calls itself.
Relational Operators - operators that show a relationship between two things.
Counter Controlled Loop - a loop that will execute a certain number of times controlled by a counter variable.
Conditional Loop - a loop that will execute as long as a certain condition is true.
Scalable - able to be changed in size or scale.
Accumulator Variable - a variable that adds a value to itself.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION