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. how to bypass loop ?

how to bypass loop ?

Scheduled Pinned Locked Moved C / C++ / MFC
databasejsontutorialquestion
4 Posts 4 Posters 4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop. What would be a cool way to accomplish that...? I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.

    for (index = 0; index < list.size(); ++index)
    {
    ... working code
    {
    ...insert test block
    }
    ... skip this working code
    } loop end

    K C J 3 Replies Last reply
    0
    • L Lost User

      I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop. What would be a cool way to accomplish that...? I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.

      for (index = 0; index < list.size(); ++index)
      {
      ... working code
      {
      ...insert test block
      }
      ... skip this working code
      } loop end

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      If I find I need to do something like this I do something like

      #ifdef DEBUG
      void foo( ... )
      {
      //
      }
      #endif

      In debug mode, then I can call foo(arg, arg, arg, ... ) when I need to. Usually this would do something like print all the elements of a collection, for example. As far as I know, you can't skip over code. You can set a break point at the top of the loop, and continue to that point. If you really want to omit portions of the loop in your debug testing the best I could suggest would be to wrap that in an #ifdef DEBUG/#endif. Alternatively, you might

      #if DEBUG == 2
      ...
      #endif

      Of course, you could use #if DEBUG <= 2, etc to get different debug levels of code when you compile. If you go that route, check with your IDE. It probably does not add a -DDEBUG to the compile command line in debug mode, so you'd have to do that yourself. If you want to have different debug levels you would pass -DDEBUG=2 (e.g.) (Linux - its probably different, but similar for windows)

      "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

      1 Reply Last reply
      0
      • L Lost User

        I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop. What would be a cool way to accomplish that...? I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.

        for (index = 0; index < list.size(); ++index)
        {
        ... working code
        {
        ...insert test block
        }
        ... skip this working code
        } loop end

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Do you mean this (skip to next iteration)

        for (int n=0; n<10; ++n)
        {
        cout << "working code A\n";
        {
        cout << "debug code, iteration = " << n << "\n";
        continue;
        }
        cout << "working code B\n";
        }

        Or, possibly, this (skip the loop)

        for (int n=0; n<10; ++n)
        {
        cout << "working code A\n";
        {

          cout << "debug code, iteration = " << n << "\\n";
          n=10; // tainting loop variables is usually not recommanded, however this is debug code...
          continue;
        }
        cout << "working code B\\n";
        

        }

        ?

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        1 Reply Last reply
        0
        • L Lost User

          I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop. What would be a cool way to accomplish that...? I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.

          for (index = 0; index < list.size(); ++index)
          {
          ... working code
          {
          ...insert test block
          }
          ... skip this working code
          } loop end

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          In C++ Macros - As noted you can remove the code entirely - You can also use a macro that resolves to a different value For code - Add a flag. - Add a class that manages flags Larger apps would use the second. Your code then tests the flag. There are various ways the flags can be set: command line, config file, database. There are various ways to manage the class itself. Could be static or use a builder pattern. Example of flag usage

          if (myFlagClass.IsSet("TestFlag131")) ....

          For systems (not just an app) can use special values in an API. The code of the target service looks for those special values and returns a fixed, or even variable, result. This is somewhat useful in verifying end to end enterprise functionality.

          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