Programming Revision – Loops

Used in programming, loops are a sequence of script which is repeated until a defined condition is reached.  The four main types of loop include for loops, while loops, do-while loops and for-each loops.

While Loops

A while loop continues to repeat through a section of code as long as a specified condition is true.  We use a while loop when we do not know the amount of times before-hand.

Example:

blog2.PNG

For Loops

Similar to a while loop, however a “for loop” repeats a block of code for a specified amount of times.  Used when you have an understanding of how many times you want to repeat the code.

Example:

blog1

Do-While Loops

Example:

blog3

For-Each Loops

Example:

blog4.PNG

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s