Difference between revisions of "Loops"

From CompSciWiki
Jump to: navigation, search
m
Line 1: Line 1:
{{1010Chapter|Introduction=Until now all your programs have been working from top to bottom. Imagine if you were to write a game to guess a secret number from 1 to 100. The entire program would consist of one hundred [[Control Structures#The If Statement|if statements]] to account for each turn to check and see if the number chosen is correct; a situation like this is where a loop will come in to play and reduce those one hundred statements into one.
+
{{1010Chapter|ChapterNum=1
 +
|Introduction=Until now all your programs have been working from top to bottom. Imagine if you were to write a game to guess a secret number from 1 to 100. The entire program would consist of one hundred [[Control Structures#The If Statement|if statements]] to account for each turn to check and see if the number chosen is correct; a situation like this is where a loop will come in to play and reduce those one hundred statements into one.
  
A loop is a [[Control Structures|control structure]] that allows you to repeat the same sequence of code as long as a given [[test condition]] evaluates to true. Every passage through this sequence of code is called an ''iteration''.  If you repeat the same sequence of code 20 times, then you have performed 20 iterations.}}
+
A loop is a [[Control Structures|control structure]] that allows you to repeat the same sequence of code as long as a given [[test condition]] evaluates to true. Every passage through this sequence of code is called an ''iteration''.  If you repeat the same sequence of code 20 times, then you have performed 20 iterations.
  
 +
|Body=
 
==[[While Loops]]==
 
==[[While Loops]]==
 
 
==[[Do-While Loops]]==
 
==[[Do-While Loops]]==
 
 
==[[For Loops]]==
 
==[[For Loops]]==
 
 
==[[nested loops|Nested Loops]]==
 
==[[nested loops|Nested Loops]]==
 
 
==[[Scope]]==
 
==[[Scope]]==
 
 
==[[Test_condition|Test Condition]]==
 
==[[Test_condition|Test Condition]]==
 
 
==[[Infinite Loops]]==
 
==[[Infinite Loops]]==
 
 
==[[Additional Information]]==
 
==[[Additional Information]]==
 
 
==[[Loop Review Questions and Exercises|Review Questions and Exercises]]==
 
==[[Loop Review Questions and Exercises|Review Questions and Exercises]]==
 +
==[[Loops Solutions|Solutions]]==
  
==[[Loops Solutions|Solutions]]==
+
 
 +
|PChapterNum=4
 +
|PChapterLink=[[Control Structures]]
 +
|NChapterNum=6
 +
|NChapterLink=[[User Defined Methods]]
 +
}}
 +
 
 +
 
 +
{{Category:COMP 1010}}

Revision as of 16:04, 10 August 2010


Wiki 1010 Table of Contents

Chapter 1

Until now all your programs have been working from top to bottom. Imagine if you were to write a game to guess a secret number from 1 to 100. The entire program would consist of one hundred if statements to account for each turn to check and see if the number chosen is correct; a situation like this is where a loop will come in to play and reduce those one hundred statements into one.

A loop is a control structure that allows you to repeat the same sequence of code as long as a given test condition evaluates to true. Every passage through this sequence of code is called an iteration. If you repeat the same sequence of code 20 times, then you have performed 20 iterations.

  Write a Program a Day Case Studies

While Loops

Do-While Loops

For Loops

Nested Loops

Scope

Test Condition

Infinite Loops

Additional Information

Review Questions and Exercises

Solutions




Chapter 0: Control Structures Table of Contents Chapter 2: User Defined Methods



Template loop detected: