How do you for loop into a while loop??

Reply

Join Date: Dec 2009
Posts: 2
Reputation: mobmgg is an unknown quantity at this point 
Solved Threads: 0
mobmgg mobmgg is offline Offline
Newbie Poster

How do you for loop into a while loop??

 
-1
  #1
Dec 2nd, 2009
for count= 1 to 50
display count
End for
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 482
Reputation: Grn Xtrm will become famous soon enough Grn Xtrm will become famous soon enough 
Solved Threads: 42
Grn Xtrm's Avatar
Grn Xtrm Grn Xtrm is offline Offline
Posting Pro in Training
 
0
  #2
Dec 2nd, 2009
The condition in the while loop will be the same as the for loop, namely the count is less than 51. Then just display the current count, and then increment the count variable by one.
This snippet (which I wrote in c++) displays what I just said,
    int count=1;
    for(count; count<51; count++)
    cout<<" "<<count;
    
    while(count<51)
    {
      cout<<" "<<count;
      count++;
    }
Both loops do the same thing. I think thats what you are looking for.
Check out my new band Apollo's Soundtrack on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2,228
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 275
BestJewSinceJC BestJewSinceJC is offline Offline
Nearly a Posting Maven
 
0
  #3
Dec 3rd, 2009
Originally Posted by mobmgg View Post
for count= 1 to 50
display count
End for
int count = 1;
while count < 51{
    display count;
    count = count + 1;
}
Last edited by Nick Evan; Dec 4th, 2009 at 3:21 am. Reason: Added code-tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3,317
Reputation: Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute 
Solved Threads: 337
Moderator
Featured Poster
Nick Evan's Avatar
Nick Evan Nick Evan is offline Offline
Cenosillicaphobiac
 
0
  #4
Dec 4th, 2009
How do you for loop into a while loop??
Click image for larger version

Name:	2824685.jpg
Views:	8
Size:	60.5 KB
ID:	12838

But on a serious note (in C++ for example):

  1. int outer = 0;
  2. while (outer < 10){
  3. for (int inner = 0; inner < 10; ++inner){
  4. cout << "outer: " << outer << " inner: " << inner << '\n';
  5. }
  6. outer++;
  7. }
Last edited by Nick Evan; Dec 4th, 2009 at 4:19 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2,228
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 275
BestJewSinceJC BestJewSinceJC is offline Offline
Nearly a Posting Maven
 
0
  #5
Dec 5th, 2009
Umm I might be confused but I just got three PMs from you (posted above me) and you just reiterated what two previous posters in here have already said. Was that really necessary?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3,317
Reputation: Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute Nick Evan has a reputation beyond repute 
Solved Threads: 337
Moderator
Featured Poster
Nick Evan's Avatar
Nick Evan Nick Evan is offline Offline
Cenosillicaphobiac
 
0
  #6
Dec 5th, 2009
Originally Posted by BestJewSinceJC View Post
Umm I might be confused but I just got three PMs from you (posted above me)
From me? I didn't send you anything.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 764 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Computer Science
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC