Difference between revisions of "Convert this While to a For"

From CompSciWiki
Jump to: navigation, search
 
Line 1: Line 1:
 
{{1010PrAD|ProblemName=Convert this While Loop to a For Loop
 
{{1010PrAD|ProblemName=Convert this While Loop to a For Loop
  
|Problem= Almost any while loop can be converted into a for loop and vice versa.  Take a look at the following sample program.  Change it so that it uses a while loop instead of a for loop
+
|Problem= Almost any while loop can be converted into a for loop and vice versa.  In fact, the for loop can be described as a while loop that iterates for a set number of times. Take a look at the following sample program.  Change it so that it uses a while loop instead of a for loop.
  
  

Revision as of 12:16, 6 April 2010

Back to the Program-A-Day homepage

Problem

Almost any while loop can be converted into a for loop and vice versa. In fact, the for loop can be described as a while loop that iterates for a set number of times. Take a look at the following sample program. Change it so that it uses a while loop instead of a for loop.

 

SideSectionTitle

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

The solution...

Code

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage