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#
  4. break; instruction

break; instruction

Scheduled Pinned Locked Moved C#
question
6 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.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    Suppose we have that part of code:

    for(...)
    {
      foreach(...)
      {
        if (...)
        {
          while(...)
          {
            -> XXX <-
          }
        }
      }
    }
    

    how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop?

    R A 2 Replies Last reply
    0
    • Y Yoyosch

      Suppose we have that part of code:

      for(...)
      {
        foreach(...)
        {
          if (...)
          {
            while(...)
            {
              -> XXX <-
            }
          }
        }
      }
      

      how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop?

      R Offline
      R Offline
      Reanalyse
      wrote on last edited by
      #2

      One way would be to turn that code into it's own subroutine and use return; to break the process and close the subroutine

      1 Reply Last reply
      0
      • Y Yoyosch

        Suppose we have that part of code:

        for(...)
        {
          foreach(...)
          {
            if (...)
            {
              while(...)
              {
                -> XXX <-
              }
            }
          }
        }
        

        how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop?

        A Offline
        A Offline
        Andres Manggini
        wrote on last edited by
        #3

        Yoyosch wrote: how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop? Use goto

        for(...)
        {
        foreach(...)
        {
        if (...)
        {
        while(...)
        {
        //-> XXX <-
        goto Gotcha;
        }
        }
        }
        }
        Gotcha:
        Console.WriteLine("Gotcha");

        Andres Manggini. Buenos Aires - Argentina.

        Y 1 Reply Last reply
        0
        • A Andres Manggini

          Yoyosch wrote: how am I supposed to exit from the place 'XXX' so that I would 'land' outside (after) the most internal ('for') loop? Use goto

          for(...)
          {
          foreach(...)
          {
          if (...)
          {
          while(...)
          {
          //-> XXX <-
          goto Gotcha;
          }
          }
          }
          }
          Gotcha:
          Console.WriteLine("Gotcha");

          Andres Manggini. Buenos Aires - Argentina.

          Y Offline
          Y Offline
          Yoyosch
          wrote on last edited by
          #4

          this is surely fastest way but is recognazed as extremaly nasty... there is no other way (line using several break;`s ?)

          L D 2 Replies Last reply
          0
          • Y Yoyosch

            this is surely fastest way but is recognazed as extremaly nasty... there is no other way (line using several break;`s ?)

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            You would have to rethink the logical program flow then. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

            1 Reply Last reply
            0
            • Y Yoyosch

              this is surely fastest way but is recognazed as extremaly nasty... there is no other way (line using several break;`s ?)

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              [code] bool error = false; for(...) { foreach(...) { if (...) { while(...) { //-> XXX <- error = true; break; } } if (error) break; } if (error) break; } [/code]

              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