Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Run to For's at once

Run to For's at once

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Steven Richardson 0

    how do you run two for's at once?

    R Offline
    R Offline
    Roger Allen
    wrote on last edited by
    #2

    int i = 0 ;
    int j = 0 ;

    for ( ; i < 10 && j < 10 ; ++i, ++j)
    {
    }

    Maybe that would do the job. I originally put i++, j++, but then I thought "Holy crap, I'll get blasted by all those c++ efficiency coders out there" Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

    S N 2 Replies Last reply
    0
    • S Steven Richardson 0

      how do you run two for's at once?

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #3

      for(i=0;i<j;i++)
      for(a=0;a<z;a++)

      Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

      S 1 Reply Last reply
      0
      • R Roger Allen

        int i = 0 ;
        int j = 0 ;

        for ( ; i < 10 && j < 10 ; ++i, ++j)
        {
        }

        Maybe that would do the job. I originally put i++, j++, but then I thought "Holy crap, I'll get blasted by all those c++ efficiency coders out there" Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

        S Offline
        S Offline
        Steven Richardson 0
        wrote on last edited by
        #4

        thanks worked great

        N 1 Reply Last reply
        0
        • S Steven Richardson 0

          thanks worked great

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #5

          Ooops! I misunderstood your question. Please ignore my reply :-) Nish :-O :-O :-O Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

          R 1 Reply Last reply
          0
          • N Nish Nishant

            for(i=0;i<j;i++)
            for(a=0;a<z;a++)

            Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

            S Offline
            S Offline
            Steven Richardson 0
            wrote on last edited by
            #6

            that is what i had but it ran the first one then the second one over till that had finnished then it ran the first one again and then started over the first one again

            N 1 Reply Last reply
            0
            • N Nish Nishant

              Ooops! I misunderstood your question. Please ignore my reply :-) Nish :-O :-O :-O Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

              R Offline
              R Offline
              Roger Allen
              wrote on last edited by
              #7

              Don't feel too bad Nish, if he had spelt his topic correctly it would have been easier to understand. Run two For's at once :-D :-D Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

              A 1 Reply Last reply
              0
              • R Roger Allen

                Don't feel too bad Nish, if he had spelt his topic correctly it would have been easier to understand. Run two For's at once :-D :-D Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

                A Offline
                A Offline
                alex barylski
                wrote on last edited by
                #8

                Roger Allen wrote: Run two For's at once I thought he was talking about beer... :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                1 Reply Last reply
                0
                • S Steven Richardson 0

                  that is what i had but it ran the first one then the second one over till that had finnished then it ran the first one again and then started over the first one again

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #9

                  Yes. The only way to actually have two 'for's running together is to have two threads. But then that's not what you want. You want two variables to be incrementted in parallel. For that you can do what Roger suggested... But there you have one 'for' with two variables getting incremented on each iteration. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

                  S 1 Reply Last reply
                  0
                  • N Nish Nishant

                    Yes. The only way to actually have two 'for's running together is to have two threads. But then that's not what you want. You want two variables to be incrementted in parallel. For that you can do what Roger suggested... But there you have one 'for' with two variables getting incremented on each iteration. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

                    S Offline
                    S Offline
                    Steven Richardson 0
                    wrote on last edited by
                    #10

                    Thanks everyone!:-D :-D :-D

                    1 Reply Last reply
                    0
                    • R Roger Allen

                      int i = 0 ;
                      int j = 0 ;

                      for ( ; i < 10 && j < 10 ; ++i, ++j)
                      {
                      }

                      Maybe that would do the job. I originally put i++, j++, but then I thought "Holy crap, I'll get blasted by all those c++ efficiency coders out there" Roger Allen Sonork 100.10016 If I'm not breathing, I'm either dead or holding my breath. A fool jabbers, while a wise man listens. But is he so wise to listen to the fool? Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge

                      N Offline
                      N Offline
                      Navier
                      wrote on last edited by
                      #11

                      You can also do: for (int i=0, int j=0; i<10 && j<10; ++i, ++j) Just wanted to blow that disgustingly UGLY bit of code out of the water. Three lines for a loop for God's sake. Talk about slack. When I were a lad we 'ad 2k and bloody grateful for it we were too. Eee, young 'uns. Anyway, what's so wrong with writing efficient code then? i1.2sqrt(u).bcos(ur)sec(c) but b4.isqrt(u).ru/16

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups