Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Loops

  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 11:03 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •