loops

This is a discussion on loops within the C Programming forums, part of the General Programming Boards category; Hi How can i write many loops that all run at the same time...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Question loops

    Hi
    How can i write many loops that all run at the same time

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    loops

    I am using "Windows me ".
    but, what i mean is how to write c proagram executes many loops at the same time

  3. #3
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    I repeat because I guess you didnt read the other message, It would be done using threads

  4. #4
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    the question is not exactly clear, and depends on the application you are writing. It may be possible using nested loop, threads and other ways. What do your loops do?
    Monday - what a way to spend a seventh of your life

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    7
    I want to write C function that draw circle at the center then it divides it to four circles each one move to the one of the four direction at the same time ,so, can you explain how can i use the nested loop?

  6. #6
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    draw them one at a time
    hello, internet!

  7. #7
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> How can i write many loops that all run at the same time

    Code:
    for(int i = 0, j = 0; i < 100, j < 100; i++, j++)
    {
        cout << i;
        cout << j;
    }
    Is this what you mean?

  8. #8
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131
    Code:
     for(i=0;i<3;i++)
          for(j=0;j<3;j++)
           {
    	cout<<"Enter the "<<i<<j<<" Location: ";
    	cin>>b[i][j];
           }

    checkout the code... the nested for loop is used to keep one value... of index of array constant.. for three alteration of the nested loop of variable.. j...
    ??????any
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please..... no C++ code on the C board.... it'll only serve to confuse the new.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    oh, sorry, i'm used to using the stream ways...

  11. #11
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131
    I have done the same mistake... as of ... face_master
    ....
    frequently .. moving b/w boards.. caused.. this mistak.. i thought i am posting code on c++ board..
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Use goto to jump through the loops so one loop executes, then jumps to the next, then jumps to the next, then returns to the original so it can increment, then jumps to the next so it can, and so on!
    Code:
    x = y = z = 0;
    
    dosomething:
    while( x < 10 )
    {
        if( x < 10 )
        {
            do_something( );
            x++;
        }
        goto dosomething1;
    }
    dosomething1:
    while( y < 10 )
    {
        if( y < 10 )
        {
            do_something1( );
            y++;
        }
        goto dosomething2;
    }
    dosomething2:
    while( z < 10 )
    {
        if( z < 10 )
        {
            do_something2( );
            z++;
        }
        goto dosomething;
    }
    That should work. Why on earth you'd want to do so is beyond me, but that'd work. Or you could just use a single control loop and put all three (or whatever) loop bodies in the same loop. This makes the mose sense, but hey, you just asked how to do it, not if it was a good idea...

    [edit]Added an if check to each loop so you could have varried numbers per loop.[/edit]

    Quzah.
    Last edited by quzah; 11-17-2002 at 12:19 PM.
    Hope is the first step on the road to disappointment.

  13. #13
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    I think it would be better to do that without gotos and labels and just use loops and the break; statement.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by beege31337
    I think it would be better to do that without gotos and labels and just use loops and the break; statement.
    You missed the entire point of the post. Sadly, humor is lost on the majority of you.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Multithreading is supported better in such languages as Java and C#
    Mr. C: Author and Instructor

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple thread for loops
    By lehe in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2009, 01:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 12:09 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 03:44 AM

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