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. The Lounge
  3. while(true) is not fun

while(true) is not fun

Scheduled Pinned Locked Moved The Lounge
52 Posts 28 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.
  • B BillWoodruff

    for (;;)
    {
    Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

    // break; // oh, go on forever
    

    }

    but, writing this was fun :wtf: suggested reading: [^]

    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

    B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #16

    well, my peers, and mentors, i intended this post as a tongue-in-cheek jiggery-pokery i hoped would not be taken seriously ... back in the days some of us fossils can remember, languages, like Fortran, had simple control structures; you had to use 'goto to exit a DO loop; that, and BASIC, are the context in which Dijkstra's famous hyperbolic essay took aim [^]. in today's high-level languages, like C#, the underlying use of jumps/gotos is abstracted away for very good reasons. if i see a while(true) in C#, i call that sloppy code that lacks documentation, and, is less maintainable, because you've got to study the interior code to figure out what, if anything, makes it stop. and, it never returns? [^]

    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

    1 Reply Last reply
    0
    • B BillWoodruff

      suggested reading: [^] :)

      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #17

      state machines are a good argument for gotos. It is impossible as far as I know, to implement every scenario possible for a deterministic finite automata based state machine without using either array based tables, or goto statements. while/for/etc don't cut it because the flow can become too complicated for those constructs. There was a Knuth paper you linked to earlier** that presented a defense of goto that is similar to my defense of it just above. ** here's the code from that paper (Example 1):

      for i := 1 step 1 until m do.
      if A[i] = x then go to found fi;
      not found: i := re+l; m := i;
      A[i] := x; B[i] := 0;
      found: B[i] := B[i]+I;

      rewritten without goto it's even worse (Example 1a):

      i:=1;
      while i < m and A[i] # x do i :-- i+1;
      if i > m then ra := i; A[i] := x; B[i] ::= 0 fi;
      B[i] := B[i]+I;

      Real programmers use butterflies

      B T G 3 Replies Last reply
      0
      • H honey the codewitch

        state machines are a good argument for gotos. It is impossible as far as I know, to implement every scenario possible for a deterministic finite automata based state machine without using either array based tables, or goto statements. while/for/etc don't cut it because the flow can become too complicated for those constructs. There was a Knuth paper you linked to earlier** that presented a defense of goto that is similar to my defense of it just above. ** here's the code from that paper (Example 1):

        for i := 1 step 1 until m do.
        if A[i] = x then go to found fi;
        not found: i := re+l; m := i;
        A[i] := x; B[i] := 0;
        found: B[i] := B[i]+I;

        rewritten without goto it's even worse (Example 1a):

        i:=1;
        while i < m and A[i] # x do i :-- i+1;
        if i > m then ra := i; A[i] := x; B[i] ::= 0 fi;
        B[i] := B[i]+I;

        Real programmers use butterflies

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #18

        i think you just hoisted my attempt to play Hamlet on his own petard :omg:

        «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

        H 1 Reply Last reply
        0
        • B BillWoodruff

          i think you just hoisted my attempt to play Hamlet on his own petard :omg:

          «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #19

          I'm all kinds of no fun today, sorry. :~

          Real programmers use butterflies

          1 Reply Last reply
          0
          • H honey the codewitch

            Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:

            var done = false;

            while(!done) {
            // do work
            }

            But every C# dev should know how to write while(true) { }

            Real programmers use butterflies

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #20

            Just a preference. But yes, guilty.

            var HellHasFrozen

            ..
            while (!HellHasFrozen)

            If you see it, good chance I wrote that code. Also (!MurlocsAttacking), used in handlers for multiple unknown exceptions. I WarCraft too much.

            Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            H 1 Reply Last reply
            0
            • L Lost User

              Just a preference. But yes, guilty.

              var HellHasFrozen

              ..
              while (!HellHasFrozen)

              If you see it, good chance I wrote that code. Also (!MurlocsAttacking), used in handlers for multiple unknown exceptions. I WarCraft too much.

              Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #21

              probably my silliest function name currently in use is _HasExtraNonsense() because the alternative (spelling out what "nonsense" means) would yield a function name as wide as the screen

              Real programmers use butterflies

              1 Reply Last reply
              0
              • B BillWoodruff

                for (;;)
                {
                Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                // break; // oh, go on forever
                

                }

                but, writing this was fun :wtf: suggested reading: [^]

                «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                M Offline
                M Offline
                Member 4480474
                wrote on last edited by
                #22

                Essential in embedded coding. Pretty much every non-OS based embedded app will have a while(1) or similar in the main code. Ditto for an OS, you can't schedule the scheduler (well, you *can*, but...).

                1 Reply Last reply
                0
                • B BillWoodruff

                  for (;;)
                  {
                  Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                  // break; // oh, go on forever
                  

                  }

                  but, writing this was fun :wtf: suggested reading: [^]

                  «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                  M Offline
                  M Offline
                  Member_14866104
                  wrote on last edited by
                  #23

                  Works better than any break point...

                  1 Reply Last reply
                  0
                  • B BillWoodruff

                    for (;;)
                    {
                    Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                    // break; // oh, go on forever
                    

                    }

                    but, writing this was fun :wtf: suggested reading: [^]

                    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                    W Offline
                    W Offline
                    Wizard of Sleeves
                    wrote on last edited by
                    #24

                    const DucksFloat = true; : : while(DucksFloat) { }

                    Nothing succeeds like a budgie without teeth.

                    R 1 Reply Last reply
                    0
                    • B BillWoodruff

                      suggested reading: [^] :)

                      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                      N Offline
                      N Offline
                      Nelek
                      wrote on last edited by
                      #25

                      aha... and?

                      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                      1 Reply Last reply
                      0
                      • B BillWoodruff

                        for (;;)
                        {
                        Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                        // break; // oh, go on forever
                        

                        }

                        but, writing this was fun :wtf: suggested reading: [^]

                        «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                        M Offline
                        M Offline
                        Martijn Smitshoek
                        wrote on last edited by
                        #26

                        The problem with any remark, comment, oneliner, if it gets overused, a number of things happen - they get a life of their own. Everybody starts to parrot this "wisdom" because of how good it sounds - the use of the term gets disconnected from the original meaning, because it is an easy, and thus lazy comment to make - instead of being helpful, or any kind of contribution to the quality and ethics of software engineering, it becomes the catchphrase of choice for individuals who want their opinion to be taken for "superior" at all cost. What everybody *should* have done instead, is work out why, or why not, they are using a particular construct, and show real professionalism that way, rather than faking it through gratuitous remarks that sit well with the boss.

                        1 Reply Last reply
                        0
                        • B BillWoodruff

                          for (;;)
                          {
                          Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                          // break; // oh, go on forever
                          

                          }

                          but, writing this was fun :wtf: suggested reading: [^]

                          «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                          R Offline
                          R Offline
                          Rene Balvert
                          wrote on last edited by
                          #27

                          for (;;)
                          {
                          Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                          goto get\_me\_out\_of\_here;
                          

                          }

                          get_me_out_of_here:

                          Now you have it all :laugh:

                          T 1 Reply Last reply
                          0
                          • B BillWoodruff

                            for (;;)
                            {
                            Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                            // break; // oh, go on forever
                            

                            }

                            but, writing this was fun :wtf: suggested reading: [^]

                            «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                            B Offline
                            B Offline
                            Bob Beechey
                            wrote on last edited by
                            #28

                            In the development phase while(true) is fine and clear. When you are clear as to what conditions must be met to break out of the loop, we can set up a meaningful boolean eg while(NoReliablStatus) or whatever. Replacing while(true) with while(notdone) is a waste of time.

                            1 Reply Last reply
                            0
                            • W Wizard of Sleeves

                              const DucksFloat = true; : : while(DucksFloat) { }

                              Nothing succeeds like a budgie without teeth.

                              R Offline
                              R Offline
                              Rage
                              wrote on last edited by
                              #29

                              "She's a duck !"

                              Do not escape reality : improve reality !

                              1 Reply Last reply
                              0
                              • B BillWoodruff

                                for (;;)
                                {
                                Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                                // break; // oh, go on forever
                                

                                }

                                but, writing this was fun :wtf: suggested reading: [^]

                                «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                                C Offline
                                C Offline
                                c6jones720
                                wrote on last edited by
                                #30

                                What about embedded systems? A lot of embedded systems have initialisation code and then the remainder of the system is handled in a single while loop, that's more or less standard practise

                                1 Reply Last reply
                                0
                                • B BillWoodruff

                                  for (;;)
                                  {
                                  Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                                  // break; // oh, go on forever
                                  

                                  }

                                  but, writing this was fun :wtf: suggested reading: [^]

                                  «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                                  realJSOPR Online
                                  realJSOPR Online
                                  realJSOP
                                  wrote on last edited by
                                  #31

                                  When I need an infinite loop, I do it accidentally.

                                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                  -----
                                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                  -----
                                  When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                  1 Reply Last reply
                                  0
                                  • B BillWoodruff

                                    for (;;)
                                    {
                                    Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                                    // break; // oh, go on forever
                                    

                                    }

                                    but, writing this was fun :wtf: suggested reading: [^]

                                    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                                    G Offline
                                    G Offline
                                    glennPattonWork3
                                    wrote on last edited by
                                    #32

                                    It's probably been said, but try to do embedded software with out infinite loops. The only time I have seen goto used in the wild was in a avionics control software!

                                    1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      state machines are a good argument for gotos. It is impossible as far as I know, to implement every scenario possible for a deterministic finite automata based state machine without using either array based tables, or goto statements. while/for/etc don't cut it because the flow can become too complicated for those constructs. There was a Knuth paper you linked to earlier** that presented a defense of goto that is similar to my defense of it just above. ** here's the code from that paper (Example 1):

                                      for i := 1 step 1 until m do.
                                      if A[i] = x then go to found fi;
                                      not found: i := re+l; m := i;
                                      A[i] := x; B[i] := 0;
                                      found: B[i] := B[i]+I;

                                      rewritten without goto it's even worse (Example 1a):

                                      i:=1;
                                      while i < m and A[i] # x do i :-- i+1;
                                      if i > m then ra := i; A[i] := x; B[i] ::= 0 fi;
                                      B[i] := B[i]+I;

                                      Real programmers use butterflies

                                      T Offline
                                      T Offline
                                      trønderen
                                      wrote on last edited by
                                      #33

                                      Knuth's "Example 1" problem using structured statements for alternate loop exits:

                                      for i in 1:m do

                                      // main loop body; may contain any number of statements:

                                      while A[i] != x; // premature loop termination if x is found

                                      exitwhile // do this on premature loop termination, i.e. "found"
                                      B[i]++;

                                      exitfor // do this if loop reaches end of (valid) A[], i.e. "not found"
                                      A[i] := x;
                                      B[i] := 1;
                                      m = i; // new search limit for subsequent x searches

                                      endfor

                                      I really miss this construct; I found it truly useful, but have seen it in a single language only, 30+ years ago. Note that both the exitwhile and exitfor clauses are within the scope of the loop statement, with access to the loop control variable and any other variable declared within the loop. (This is essential to the usability of the construct.)

                                      H 1 Reply Last reply
                                      0
                                      • H honey the codewitch

                                        Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:

                                        var done = false;

                                        while(!done) {
                                        // do work
                                        }

                                        But every C# dev should know how to write while(true) { }

                                        Real programmers use butterflies

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

                                        honey the codewitch wrote:

                                        But every C# dev should know how to write while(true) { }

                                        while (true)
                                        {
                                        Console.WriteLine("C# is better than Javascript!");
                                        }

                                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                        1 Reply Last reply
                                        0
                                        • R Rene Balvert

                                          for (;;)
                                          {
                                          Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");

                                          goto get\_me\_out\_of\_here;
                                          

                                          }

                                          get_me_out_of_here:

                                          Now you have it all :laugh:

                                          T Offline
                                          T Offline
                                          trønderen
                                          wrote on last edited by
                                          #35

                                          #define ever (;;)

                                          would allow you to write

                                          for ever {...}

                                          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