Is this loop construct only available using goto's???

This is a discussion on Is this loop construct only available using goto's??? within the C Programming forums, part of the General Programming Boards category; I know the answer must be NO!!! , but I can't think of a direct way of doing this. Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    14

    Is this loop construct only available using goto's???

    I know the answer must be NO!!!, but I can't think of a direct way of doing this.
    Code:
    BEGIN LOOP
    loop statements;
    .
    .
    .
    TEST(test_condition)
    update statements;
    .
    .
    .
    END LOOP
    I hope that was clear. The main features I am trying to create are these: the loop iterates once before testing anything. Then it tests the condition BEFORE running the update code. Lastly, the update code contains multiple statements. It seems to me the none of for, while and dowhile loops really want to do this, although it would be possible. Implementing with goto's is really, really easy, but I was told to never ever use them.

    Thanks a bunch.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    erm, what's wrong with while loop?

    Code:
    while(1) {
       loop statements;
    .
    .
    .
    TEST(test_condition)
    update statements;
    .
    .
    .
    }

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    14

    Of Course!!!

    Thank you!! I knew I was being thick! I was just stuck with the idea that the test part of the standard loop structure had to actually be the test.

    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poll event loop
    By rogster001 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2009, 05:28 AM
  2. need help with a loop
    By Darkw1sh in forum C Programming
    Replies: 19
    Last Post: 09-13-2009, 10:46 PM
  3. funny-looking while loop
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2009, 12:54 AM
  4. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21