Loops are essential programming tools that let you repeat instructions... Show more
Sign up to see the contentIt's free!
Access to all documents
Improve your grades
Join milions of students
Subjects
Triangle Congruence and Similarity Theorems
Triangle Properties and Classification
Linear Equations and Graphs
Geometric Angle Relationships
Trigonometric Functions and Identities
Equation Solving Techniques
Circle Geometry Fundamentals
Division Operations and Methods
Basic Differentiation Rules
Exponent and Logarithm Properties
Show all topics
Human Organ Systems
Reproductive Cell Cycles
Biological Sciences Subdisciplines
Cellular Energy Metabolism
Autotrophic Energy Processes
Inheritance Patterns and Principles
Biomolecular Structure and Organization
Cell Cycle and Division Mechanics
Cellular Organization and Development
Biological Structural Organization
Show all topics
Chemical Sciences and Applications
Atomic Structure and Composition
Molecular Electron Structure Representation
Atomic Electron Behavior
Matter Properties and Water
Mole Concept and Calculations
Gas Laws and Behavior
Periodic Table Organization
Chemical Thermodynamics Fundamentals
Chemical Bond Types and Properties
Show all topics
European Renaissance and Enlightenment
European Cultural Movements 800-1920
American Revolution Era 1763-1797
American Civil War 1861-1865
Global Imperial Systems
Mongol and Chinese Dynasties
U.S. Presidents and World Leaders
Historical Sources and Documentation
World Wars Era and Impact
World Religious Systems
Show all topics
Classic and Contemporary Novels
Literary Character Analysis
Rhetorical Theory and Practice
Classic Literary Narratives
Reading Analysis and Interpretation
Narrative Structure and Techniques
English Language Components
Influential English-Language Authors
Basic Sentence Structure
Narrative Voice and Perspective
Show all topics
146
•
Feb 16, 2026
•
Marliya Brown
@marliyabrown_sdmc
Loops are essential programming tools that let you repeat instructions... Show more











Loops help you repeat sections of code without having to copy and paste the same instructions multiple times. They're like telling a computer "keep doing this until I tell you to stop."
When you need to print numbers 1-10 or add up a series of values, loops make this task simple. The two main types we'll explore are the WHILE loop (which checks a condition first) and the DO-WHILE loop (which runs at least once before checking).
Quick Tip: Think of loops like a broken record that keeps playing the same part of a song until someone lifts the needle!

Each time a loop runs through its code block completely, it's called an iteration. For example, if you wanted to print numbers 1 to 10, your loop would go through 10 iterations - running once for each number.
The beauty of loops is that you don't need to write ten separate print commands. You write one print command inside a loop structure, and it automatically repeats with different values each time.
Think of iterations like laps around a track - each complete circuit is one iteration, and you can set exactly how many laps you want to run.

An accumulator is like a running total that stores values during a process. It's a temporary storage location that keeps track of calculations as your loop runs.
For example, if you wanted to find the sum of numbers 1-10, you'd use an accumulator that starts at 0. Each time through the loop, you'd add the current number to this accumulator.
This technique is incredibly powerful for calculating sums, averages, and other running totals as your program processes multiple values.
Remember: Always initialize your accumulator (usually to 0 for addition or 1 for multiplication) before entering the loop!

Let's say we want to add up the numbers 1 through 10 (1+2+3+4+5+6+7+8+9+10), which equals 55.
To solve this with a loop, we'd create 10 iterations, with each one adding the current number to our running total. This approach works for any size list of numbers - whether you're adding 10 or 10,000 values!
The loop elegantly handles the repetitive addition without us needing to write the same code over and over.

Instead of just printing each number as the loop counts from 1 to 10, we'll store the increasing sum in an accumulator variable. This variable temporarily holds the current total until all 10 iterations are complete.
The process works like this: start with an accumulator set to 0, then for each iteration, add the current number to the accumulator. By the end of all iterations, the accumulator contains the final sum.
While we've focused on addition here, accumulators work just as well for multiplication and other mathematical operations too.

A counter is a special variable that tracks how many iterations a loop has performed. It's like a lap counter in a race that helps you know when to stop.
Counters typically start at a specific value (like 1 or 0) and increase or decrease with each loop iteration. They serve two important purposes: controlling when the loop should end and providing values to use in calculations.
For example, in our sum program, the counter would start at 1, provide each number to add to the accumulator, and increase until it reaches 10, signaling the loop to stop.
Pro Tip: Choose meaningful names for counter variables like "count" or "i" (short for iterator) to make your code more readable!

An infinite loop is exactly what it sounds like - a loop that never ends! This usually happens due to logical errors in your code.
Infinite loops occur when the condition that's supposed to eventually stop the loop never becomes false. For example, if you forget to increment your counter variable, the loop will keep checking the same condition forever.
These are programming mistakes you'll want to avoid, as they can cause your program to freeze or crash. Always make sure your loop has a clear way to terminate.

A pre-condition loop checks if a condition is true before executing any code inside the loop. The WHILE loop is a perfect example of this.
With a WHILE loop, the computer first evaluates the condition. If it's true, the code inside the loop runs. After completing the loop body, it goes back to check the condition again. This cycle continues until the condition becomes false.
This means that if the condition is false from the start, the loop's code might never execute at all. This is perfect for situations where you might not need to run the loop even once.

Unlike pre-condition loops, a post-condition loop like DO-WHILE executes its code first, then checks the condition afterward.
The biggest difference is that a DO-WHILE loop always executes at least once, even if the condition is false from the beginning. After running the code, it checks if the condition is true. If so, it loops again; if not, it exits.
This type of loop is ideal when you need to guarantee that certain code runs at least one time before checking any conditions.
Important: Use DO-WHILE when you absolutely need the loop to execute at least once, regardless of conditions.

Now that we understand the theory behind loops and their flowcharts, it's time to start writing actual code using WHILE, FOR, and DO-WHILE loops.
Each loop type has specific syntax rules and use cases. The choice between them depends on your specific programming needs - whether you need to check a condition before running any code or ensure the code runs at least once.
In the following sections, we'll explore each loop type with practical examples you can try yourself.
Our AI companion is specifically built for the needs of students. Based on the millions of content pieces we have on the platform we can provide truly meaningful and relevant answers to students. But its not only about answers, the companion is even more about guiding students through their daily learning challenges, with personalised study plans, quizzes or content pieces in the chat and 100% personalisation based on the students skills and developments.
You can download the app in the Google Play Store and in the Apple App Store.
That's right! Enjoy free access to study content, connect with fellow students, and get instant help – all at your fingertips.
App Store
Google Play
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
Stefan S
iOS user
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Samantha Klich
Android user
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.
Anna
iOS user
I think it’s very much worth it and you’ll end up using it a lot once you get the hang of it and even after looking at others notes you can still ask your Artificial intelligence buddy the question and ask to simplify it if you still don’t get it!!! In the end I think it’s worth it 😊👍 ⚠️Also DID I MENTION ITS FREEE YOU DON’T HAVE TO PAY FOR ANYTHING AND STILL GET YOUR GRADES IN PERFECTLY❗️❗️⚠️
Thomas R
iOS user
Knowunity is the BEST app I’ve used in a minute. This is not an ai review or anything this is genuinely coming from a 7th grade student (I know 2011 im young) but dude this app is a 10/10 i have maintained a 3.8 gpa and have plenty of time for gaming. I love it and my mom is just happy I got good grades
Brad T
Android user
Not only did it help me find the answer but it also showed me alternative ways to solve it. I was horrible in math and science but now I have an a in both subjects. Thanks for the help🤍🤍
David K
iOS user
The app's just great! All I have to do is enter the topic in the search bar and I get the response real fast. I don't have to watch 10 YouTube videos to understand something, so I'm saving my time. Highly recommended!
Sudenaz Ocak
Android user
In school I was really bad at maths but thanks to the app, I am doing better now. I am so grateful that you made the app.
Greenlight Bonnie
Android user
I found this app a couple years ago and it has only gotten better since then. I really love it because it can help with written questions and photo questions. Also, it can find study guides that other people have made as well as flashcard sets and practice tests. The free version is also amazing for students who might not be able to afford it. Would 100% recommend
Aubrey
iOS user
Best app if you're in Highschool or Junior high. I have been using this app for 2 school years and it's the best, it's good if you don't have anyone to help you with school work.😋🩷🎀
Marco B
iOS user
THE QUIZES AND FLASHCARDS ARE SO USEFUL AND I LOVE Knowunity AI. IT ALSO IS LITREALLY LIKE CHATGPT BUT SMARTER!! HELPED ME WITH MY MASCARA PROBLEMS TOO!! AS WELL AS MY REAL SUBJECTS ! DUHHH 😍😁😲🤑💗✨🎀😮
Elisha
iOS user
This app is phenomenal down to the correct info and the various topics you can study! I greatly recommend it for people who struggle with procrastination and those who need homework help. It has been perfectly accurate for world 1 history as far as I’ve seen! Geometry too!
Paul T
iOS user
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
Stefan S
iOS user
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Samantha Klich
Android user
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.
Anna
iOS user
I think it’s very much worth it and you’ll end up using it a lot once you get the hang of it and even after looking at others notes you can still ask your Artificial intelligence buddy the question and ask to simplify it if you still don’t get it!!! In the end I think it’s worth it 😊👍 ⚠️Also DID I MENTION ITS FREEE YOU DON’T HAVE TO PAY FOR ANYTHING AND STILL GET YOUR GRADES IN PERFECTLY❗️❗️⚠️
Thomas R
iOS user
Knowunity is the BEST app I’ve used in a minute. This is not an ai review or anything this is genuinely coming from a 7th grade student (I know 2011 im young) but dude this app is a 10/10 i have maintained a 3.8 gpa and have plenty of time for gaming. I love it and my mom is just happy I got good grades
Brad T
Android user
Not only did it help me find the answer but it also showed me alternative ways to solve it. I was horrible in math and science but now I have an a in both subjects. Thanks for the help🤍🤍
David K
iOS user
The app's just great! All I have to do is enter the topic in the search bar and I get the response real fast. I don't have to watch 10 YouTube videos to understand something, so I'm saving my time. Highly recommended!
Sudenaz Ocak
Android user
In school I was really bad at maths but thanks to the app, I am doing better now. I am so grateful that you made the app.
Greenlight Bonnie
Android user
I found this app a couple years ago and it has only gotten better since then. I really love it because it can help with written questions and photo questions. Also, it can find study guides that other people have made as well as flashcard sets and practice tests. The free version is also amazing for students who might not be able to afford it. Would 100% recommend
Aubrey
iOS user
Best app if you're in Highschool or Junior high. I have been using this app for 2 school years and it's the best, it's good if you don't have anyone to help you with school work.😋🩷🎀
Marco B
iOS user
THE QUIZES AND FLASHCARDS ARE SO USEFUL AND I LOVE Knowunity AI. IT ALSO IS LITREALLY LIKE CHATGPT BUT SMARTER!! HELPED ME WITH MY MASCARA PROBLEMS TOO!! AS WELL AS MY REAL SUBJECTS ! DUHHH 😍😁😲🤑💗✨🎀😮
Elisha
iOS user
This app is phenomenal down to the correct info and the various topics you can study! I greatly recommend it for people who struggle with procrastination and those who need homework help. It has been perfectly accurate for world 1 history as far as I’ve seen! Geometry too!
Paul T
iOS user
Marliya Brown
@marliyabrown_sdmc
Loops are essential programming tools that let you repeat instructions automatically. They save time and make your code more efficient by executing the same code multiple times with different values, rather than writing the same code over and over again.... Show more

Access to all documents
Improve your grades
Join milions of students
Loops help you repeat sections of code without having to copy and paste the same instructions multiple times. They're like telling a computer "keep doing this until I tell you to stop."
When you need to print numbers 1-10 or add up a series of values, loops make this task simple. The two main types we'll explore are the WHILE loop (which checks a condition first) and the DO-WHILE loop (which runs at least once before checking).
Quick Tip: Think of loops like a broken record that keeps playing the same part of a song until someone lifts the needle!

Access to all documents
Improve your grades
Join milions of students
Each time a loop runs through its code block completely, it's called an iteration. For example, if you wanted to print numbers 1 to 10, your loop would go through 10 iterations - running once for each number.
The beauty of loops is that you don't need to write ten separate print commands. You write one print command inside a loop structure, and it automatically repeats with different values each time.
Think of iterations like laps around a track - each complete circuit is one iteration, and you can set exactly how many laps you want to run.

Access to all documents
Improve your grades
Join milions of students
An accumulator is like a running total that stores values during a process. It's a temporary storage location that keeps track of calculations as your loop runs.
For example, if you wanted to find the sum of numbers 1-10, you'd use an accumulator that starts at 0. Each time through the loop, you'd add the current number to this accumulator.
This technique is incredibly powerful for calculating sums, averages, and other running totals as your program processes multiple values.
Remember: Always initialize your accumulator (usually to 0 for addition or 1 for multiplication) before entering the loop!

Access to all documents
Improve your grades
Join milions of students
Let's say we want to add up the numbers 1 through 10 (1+2+3+4+5+6+7+8+9+10), which equals 55.
To solve this with a loop, we'd create 10 iterations, with each one adding the current number to our running total. This approach works for any size list of numbers - whether you're adding 10 or 10,000 values!
The loop elegantly handles the repetitive addition without us needing to write the same code over and over.

Access to all documents
Improve your grades
Join milions of students
Instead of just printing each number as the loop counts from 1 to 10, we'll store the increasing sum in an accumulator variable. This variable temporarily holds the current total until all 10 iterations are complete.
The process works like this: start with an accumulator set to 0, then for each iteration, add the current number to the accumulator. By the end of all iterations, the accumulator contains the final sum.
While we've focused on addition here, accumulators work just as well for multiplication and other mathematical operations too.

Access to all documents
Improve your grades
Join milions of students
A counter is a special variable that tracks how many iterations a loop has performed. It's like a lap counter in a race that helps you know when to stop.
Counters typically start at a specific value (like 1 or 0) and increase or decrease with each loop iteration. They serve two important purposes: controlling when the loop should end and providing values to use in calculations.
For example, in our sum program, the counter would start at 1, provide each number to add to the accumulator, and increase until it reaches 10, signaling the loop to stop.
Pro Tip: Choose meaningful names for counter variables like "count" or "i" (short for iterator) to make your code more readable!

Access to all documents
Improve your grades
Join milions of students
An infinite loop is exactly what it sounds like - a loop that never ends! This usually happens due to logical errors in your code.
Infinite loops occur when the condition that's supposed to eventually stop the loop never becomes false. For example, if you forget to increment your counter variable, the loop will keep checking the same condition forever.
These are programming mistakes you'll want to avoid, as they can cause your program to freeze or crash. Always make sure your loop has a clear way to terminate.

Access to all documents
Improve your grades
Join milions of students
A pre-condition loop checks if a condition is true before executing any code inside the loop. The WHILE loop is a perfect example of this.
With a WHILE loop, the computer first evaluates the condition. If it's true, the code inside the loop runs. After completing the loop body, it goes back to check the condition again. This cycle continues until the condition becomes false.
This means that if the condition is false from the start, the loop's code might never execute at all. This is perfect for situations where you might not need to run the loop even once.

Access to all documents
Improve your grades
Join milions of students
Unlike pre-condition loops, a post-condition loop like DO-WHILE executes its code first, then checks the condition afterward.
The biggest difference is that a DO-WHILE loop always executes at least once, even if the condition is false from the beginning. After running the code, it checks if the condition is true. If so, it loops again; if not, it exits.
This type of loop is ideal when you need to guarantee that certain code runs at least one time before checking any conditions.
Important: Use DO-WHILE when you absolutely need the loop to execute at least once, regardless of conditions.

Access to all documents
Improve your grades
Join milions of students
Now that we understand the theory behind loops and their flowcharts, it's time to start writing actual code using WHILE, FOR, and DO-WHILE loops.
Each loop type has specific syntax rules and use cases. The choice between them depends on your specific programming needs - whether you need to check a condition before running any code or ensure the code runs at least once.
In the following sections, we'll explore each loop type with practical examples you can try yourself.
Our AI companion is specifically built for the needs of students. Based on the millions of content pieces we have on the platform we can provide truly meaningful and relevant answers to students. But its not only about answers, the companion is even more about guiding students through their daily learning challenges, with personalised study plans, quizzes or content pieces in the chat and 100% personalisation based on the students skills and developments.
You can download the app in the Google Play Store and in the Apple App Store.
That's right! Enjoy free access to study content, connect with fellow students, and get instant help – all at your fingertips.
12
Smart Tools NEW
Transform this note into: ✓ 50+ Practice Questions ✓ Interactive Flashcards ✓ Full Practice Test ✓ Essay Outlines
App Store
Google Play
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
Stefan S
iOS user
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Samantha Klich
Android user
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.
Anna
iOS user
I think it’s very much worth it and you’ll end up using it a lot once you get the hang of it and even after looking at others notes you can still ask your Artificial intelligence buddy the question and ask to simplify it if you still don’t get it!!! In the end I think it’s worth it 😊👍 ⚠️Also DID I MENTION ITS FREEE YOU DON’T HAVE TO PAY FOR ANYTHING AND STILL GET YOUR GRADES IN PERFECTLY❗️❗️⚠️
Thomas R
iOS user
Knowunity is the BEST app I’ve used in a minute. This is not an ai review or anything this is genuinely coming from a 7th grade student (I know 2011 im young) but dude this app is a 10/10 i have maintained a 3.8 gpa and have plenty of time for gaming. I love it and my mom is just happy I got good grades
Brad T
Android user
Not only did it help me find the answer but it also showed me alternative ways to solve it. I was horrible in math and science but now I have an a in both subjects. Thanks for the help🤍🤍
David K
iOS user
The app's just great! All I have to do is enter the topic in the search bar and I get the response real fast. I don't have to watch 10 YouTube videos to understand something, so I'm saving my time. Highly recommended!
Sudenaz Ocak
Android user
In school I was really bad at maths but thanks to the app, I am doing better now. I am so grateful that you made the app.
Greenlight Bonnie
Android user
I found this app a couple years ago and it has only gotten better since then. I really love it because it can help with written questions and photo questions. Also, it can find study guides that other people have made as well as flashcard sets and practice tests. The free version is also amazing for students who might not be able to afford it. Would 100% recommend
Aubrey
iOS user
Best app if you're in Highschool or Junior high. I have been using this app for 2 school years and it's the best, it's good if you don't have anyone to help you with school work.😋🩷🎀
Marco B
iOS user
THE QUIZES AND FLASHCARDS ARE SO USEFUL AND I LOVE Knowunity AI. IT ALSO IS LITREALLY LIKE CHATGPT BUT SMARTER!! HELPED ME WITH MY MASCARA PROBLEMS TOO!! AS WELL AS MY REAL SUBJECTS ! DUHHH 😍😁😲🤑💗✨🎀😮
Elisha
iOS user
This app is phenomenal down to the correct info and the various topics you can study! I greatly recommend it for people who struggle with procrastination and those who need homework help. It has been perfectly accurate for world 1 history as far as I’ve seen! Geometry too!
Paul T
iOS user
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
Stefan S
iOS user
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Samantha Klich
Android user
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.
Anna
iOS user
I think it’s very much worth it and you’ll end up using it a lot once you get the hang of it and even after looking at others notes you can still ask your Artificial intelligence buddy the question and ask to simplify it if you still don’t get it!!! In the end I think it’s worth it 😊👍 ⚠️Also DID I MENTION ITS FREEE YOU DON’T HAVE TO PAY FOR ANYTHING AND STILL GET YOUR GRADES IN PERFECTLY❗️❗️⚠️
Thomas R
iOS user
Knowunity is the BEST app I’ve used in a minute. This is not an ai review or anything this is genuinely coming from a 7th grade student (I know 2011 im young) but dude this app is a 10/10 i have maintained a 3.8 gpa and have plenty of time for gaming. I love it and my mom is just happy I got good grades
Brad T
Android user
Not only did it help me find the answer but it also showed me alternative ways to solve it. I was horrible in math and science but now I have an a in both subjects. Thanks for the help🤍🤍
David K
iOS user
The app's just great! All I have to do is enter the topic in the search bar and I get the response real fast. I don't have to watch 10 YouTube videos to understand something, so I'm saving my time. Highly recommended!
Sudenaz Ocak
Android user
In school I was really bad at maths but thanks to the app, I am doing better now. I am so grateful that you made the app.
Greenlight Bonnie
Android user
I found this app a couple years ago and it has only gotten better since then. I really love it because it can help with written questions and photo questions. Also, it can find study guides that other people have made as well as flashcard sets and practice tests. The free version is also amazing for students who might not be able to afford it. Would 100% recommend
Aubrey
iOS user
Best app if you're in Highschool or Junior high. I have been using this app for 2 school years and it's the best, it's good if you don't have anyone to help you with school work.😋🩷🎀
Marco B
iOS user
THE QUIZES AND FLASHCARDS ARE SO USEFUL AND I LOVE Knowunity AI. IT ALSO IS LITREALLY LIKE CHATGPT BUT SMARTER!! HELPED ME WITH MY MASCARA PROBLEMS TOO!! AS WELL AS MY REAL SUBJECTS ! DUHHH 😍😁😲🤑💗✨🎀😮
Elisha
iOS user
This app is phenomenal down to the correct info and the various topics you can study! I greatly recommend it for people who struggle with procrastination and those who need homework help. It has been perfectly accurate for world 1 history as far as I’ve seen! Geometry too!
Paul T
iOS user