Loops are things in programming languages and operating systems that process stuff. Loops do what they sound like. If you were to run around in circles you are also looping around in a circle. So, if you can imagine running around in circles in the same spot, you have the ability to process stuff while you loop around in circles.
Processing stuff while you run around in circles could include catching something that someone throws to you, a ball for instance. In turn, you could throw the ball as you run around in circles as well. All the while, processing stuff that comes in and out of the loop.
That is what a loop structure is in programming languages. So let’s look at some examples.
WordPress
WordPress is written in a language called PHP which is a scripting language that is well suited for web application development. A great resource to read up and learn more about PHP is the W3 Schools website where they walk you through PHP in their PHP Tutorial.
Here is the WordPress loop that processes is the common index.php page.
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
The while and endwhile statements are the loop structure that processes what shows up on a common WordPress blog home page - blog posts. My interpretations is, “Run around in a circle while blog posts show up on the page. When there are no more blog posts, quit.”
As you look at loop structures in PHP as well as other languages, you’ll find out that there are different types of loop structures used for different purposes. These include statements like do..while, for, and foreach. Again visit the PHP Tutorial at the W3 Schools website to study more examples.
Visual Basic
In Visual Basic one type of loop structure looks like this:
for x = 1 to 100
debug.print(x)
next x
The Visual Basic loop tells us that x will count from 1 to 100 as the loop executes. There are other loop structures that can be used in Visual Basic just like any other language to process various actions in various ways for various reasons.
Windows Operating System
At another level, the Windows Operating System even has loop structures. Whenever you type on the keyboard or click the mouse a message is sent to a queue. The message queue (or list) gets processed and sends those messages to a program running in Windows where the program then interprets what the message is and what to do about it.
Once you understand how a loop structure works it’s pretty easy to figure them out in other languages. It then becomes a task of figuring out the nuances of those loop structures for each language. They don’t always work the same in every programming language.
Photo Credit: frostnova



{ 1 comment… read it below or add one }
Paul 11.29.08 at 12:05 pm
Java has a good loop type which loops through the values of an array.
eg.
int[] numberList = {1,5,7,22};
for (int getNum : numberList)
{
System.out.println(”Count is: ” + getNum);
}
This also works for character values eg. peopleList = {”John”,”Bill”}
Pauls last blog post..HTC Touch HD review