Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2008, 12:02 AM   PM User | #1
Peetree1201
New to the CF scene

 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Peetree1201 is an unknown quantity at this point
Loops

Okay, so I've been taking computer programming for about 9 weeks now, and I love it! But does anyone have any tips for completing do while loops?

Last edited by Peetree1201; 10-23-2008 at 10:03 PM..
Peetree1201 is offline   Reply With Quote
Old 10-24-2008, 12:41 PM   PM User | #2
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
What do you mean by "completing"?

A while loop and a for loop are just different ways of writing the same thing.

I'm going to give examples in C because you have not specified a language and many languages share C syntax.

Code:
for(a; b; c)
{
  d;
}
is about the same as
Code:
a;
while(b)
{
  d;
  c;
}
if that helps.

Code:
a;
do
{
  d;
  c;
}
while(b);
is similar but "b" only gets evaluated after one pass, so it is guaranteed to run once.

You can also use "continue" and "break" to either stop the current pass of the loop and continue on to the next pass of the loop or break out of the loop entirely, respectively.
ghell is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 AM.


Advertisement
Log in to turn off these ads.