how does this for loop translate to english?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?How does the Java 'for each' loop work?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?A 'for' loop to iterate over an enum in JavaLoop through an array in JavaScriptHow do I convert a String to an int in Java?Why does this code using random strings print “hello world”?

Why are electrically insulating heatsinks so rare? Is it just cost?

Why can't I see bouncing of a switch on an oscilloscope?

Does detail obscure or enhance action?

tikz convert color string to hex value

dbcc cleantable batch size explanation

Important Resources for Dark Age Civilizations?

Languages that we cannot (dis)prove to be Context-Free

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

How old can references or sources in a thesis be?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

High voltage LED indicator 40-1000 VDC without additional power supply

How to format long polynomial?

meaning of に in 本当に?

What's the point of deactivating Num Lock on login screens?

How can I make my BBEG immortal short of making them a Lich or Vampire?

Cross compiling for RPi - error while loading shared libraries

NMaximize is not converging to a solution

What are these boxed doors outside store fronts in New York?

Paid for article while in US on F-1 visa?

What would happen to a modern skyscraper if it rains micro blackholes?

Is it possible to do 50 km distance without any previous training?

What's the output of a record needle playing an out-of-speed record

Why is consensus so controversial in Britain?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)



how does this for loop translate to english?


How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?How does the Java 'for each' loop work?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?A 'for' loop to iterate over an enum in JavaLoop through an array in JavaScriptHow do I convert a String to an int in Java?Why does this code using random strings print “hello world”?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















So basically I got this code from my professor but I've never seen anyone write a for loop like this. I dont even know how to start reading it? Can someone tell me how you would read this in English first and then what's the best way to use this in a for loop?
also dont think this info was is needed but just incase, we're working on linkedlists in java.



Thanks in advance



 public void delete(Object el) // find and remove el; 
if (head != null) // if non-empty list;
if (el.equals(head.info)) // if head needs to be removed;
head = head.next;
else
SLLNode pred = head, tmp = head.next;
for ( ; tmp != null && !(tmp.info.equals(el));
pred = pred.next, tmp = tmp.next);
if (tmp != null) // if found
pred.next = tmp.next;











share|improve this question




























    0















    So basically I got this code from my professor but I've never seen anyone write a for loop like this. I dont even know how to start reading it? Can someone tell me how you would read this in English first and then what's the best way to use this in a for loop?
    also dont think this info was is needed but just incase, we're working on linkedlists in java.



    Thanks in advance



     public void delete(Object el) // find and remove el; 
    if (head != null) // if non-empty list;
    if (el.equals(head.info)) // if head needs to be removed;
    head = head.next;
    else
    SLLNode pred = head, tmp = head.next;
    for ( ; tmp != null && !(tmp.info.equals(el));
    pred = pred.next, tmp = tmp.next);
    if (tmp != null) // if found
    pred.next = tmp.next;











    share|improve this question
























      0












      0








      0








      So basically I got this code from my professor but I've never seen anyone write a for loop like this. I dont even know how to start reading it? Can someone tell me how you would read this in English first and then what's the best way to use this in a for loop?
      also dont think this info was is needed but just incase, we're working on linkedlists in java.



      Thanks in advance



       public void delete(Object el) // find and remove el; 
      if (head != null) // if non-empty list;
      if (el.equals(head.info)) // if head needs to be removed;
      head = head.next;
      else
      SLLNode pred = head, tmp = head.next;
      for ( ; tmp != null && !(tmp.info.equals(el));
      pred = pred.next, tmp = tmp.next);
      if (tmp != null) // if found
      pred.next = tmp.next;











      share|improve this question














      So basically I got this code from my professor but I've never seen anyone write a for loop like this. I dont even know how to start reading it? Can someone tell me how you would read this in English first and then what's the best way to use this in a for loop?
      also dont think this info was is needed but just incase, we're working on linkedlists in java.



      Thanks in advance



       public void delete(Object el) // find and remove el; 
      if (head != null) // if non-empty list;
      if (el.equals(head.info)) // if head needs to be removed;
      head = head.next;
      else
      SLLNode pred = head, tmp = head.next;
      for ( ; tmp != null && !(tmp.info.equals(el));
      pred = pred.next, tmp = tmp.next);
      if (tmp != null) // if found
      pred.next = tmp.next;








      java for-loop linked-list






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 at 1:12









      Alan KamaliAlan Kamali

      11




      11






















          3 Answers
          3






          active

          oldest

          votes


















          2














          for(x;y;z) ...; 


          is equivalent to



          x;
          while(y)
          ...;
          z;



          So



           for ( ; tmp != null && !(tmp.info.equals(el));
          pred = pred.next, tmp = tmp.next);


          is equivalent to:



          while(tmp != null && !(tmp.info.equals(el))) 
          pred = pred.next, tmp = tmp.next;



          In English, it would be something like




          Until we find the element we're looking for, or the end of the list: update the predecessor and current element to their respective next elements







          share|improve this answer






























            1














            The Java for loop has the form:



            for (initialization; termination; increment) 
            statement(s);



            Your sample code is:



            for ( ; tmp != null && !(tmp.info.equals(el));
            pred = pred.next, tmp = tmp.next);


            If we break it down, you can see there:



            • is no initialization step

            • two parts to the termination

            • two (comma separated) statements in the increment step

            In rough English:



            • keep looping until tmp is null or tmp matches the element to be deleted, ie. iterate through the list until we reach the end or find a match

            • each time through the loop, increment pred and tmp by pointing them to the next item





            share|improve this answer

























            • oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

              – Alan Kamali
              Mar 9 at 1:50











            • No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

              – dave
              Mar 9 at 4:01











            • what would even be the point of an infinite loop? when would you want to use such a thing in real life?

              – Alan Kamali
              Mar 9 at 4:13











            • Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

              – dave
              Mar 10 at 5:23


















            0














            A for loop is made up of four parts: the initialization expression, the termination expression, the increment expression, and the body.



            (There's also a for-each style loop which has different syntax, but that's not what we're talking about here.)



            So to parse this apart:



            • The initialization expression is empty (nothing before the first ;)

            • The termination expression is tmp != null && !(tmp.info.equals(el)

            • The increment expression is pred = pred.next, tmp = tmp.next

            • The body is also empty (after the closing ) of the for expression, the next statement is just ;

            In plain English:




            As long as tmp is not null, but tmp.info is not our desired element el, continue moving pred and tmp to point to the successor elements in the linked list.




            The termination condition of this loop is that either tmp is null (if el was not an element of the list at all), or pred points to the node before the node that had el as a value, and tmp points to the node that has el as a value.



            Note that this code is written in a very terse style. This kind of style was common for low-level code 20+ years ago; nowadays when I see code like this it makes me think it was written by an old-timer.



            I would probably write the same method like this instead:



            public void delete(Object item) 
            if (head == null)
            // The list is empty; we have no work to do.
            return;

            if (head.info.equals(item))
            // We're deleting the head of the list; just update our head reference.
            head = head.next;
            return;

            SLLNode previous = head;
            SLLNode current = head.next;
            while (current != null)
            if (current.info.equals(item))
            // Update the list to skip the current node, then we're done.
            previous.next = current.next;
            return;

            // Move to the next node in the list.
            previous = current;
            current = current.next;

            // If we reached this point, the item was not found in this list.
            // There's nothing to do, so we're done anyway.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073043%2fhow-does-this-for-loop-translate-to-english%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              for(x;y;z) ...; 


              is equivalent to



              x;
              while(y)
              ...;
              z;



              So



               for ( ; tmp != null && !(tmp.info.equals(el));
              pred = pred.next, tmp = tmp.next);


              is equivalent to:



              while(tmp != null && !(tmp.info.equals(el))) 
              pred = pred.next, tmp = tmp.next;



              In English, it would be something like




              Until we find the element we're looking for, or the end of the list: update the predecessor and current element to their respective next elements







              share|improve this answer



























                2














                for(x;y;z) ...; 


                is equivalent to



                x;
                while(y)
                ...;
                z;



                So



                 for ( ; tmp != null && !(tmp.info.equals(el));
                pred = pred.next, tmp = tmp.next);


                is equivalent to:



                while(tmp != null && !(tmp.info.equals(el))) 
                pred = pred.next, tmp = tmp.next;



                In English, it would be something like




                Until we find the element we're looking for, or the end of the list: update the predecessor and current element to their respective next elements







                share|improve this answer

























                  2












                  2








                  2







                  for(x;y;z) ...; 


                  is equivalent to



                  x;
                  while(y)
                  ...;
                  z;



                  So



                   for ( ; tmp != null && !(tmp.info.equals(el));
                  pred = pred.next, tmp = tmp.next);


                  is equivalent to:



                  while(tmp != null && !(tmp.info.equals(el))) 
                  pred = pred.next, tmp = tmp.next;



                  In English, it would be something like




                  Until we find the element we're looking for, or the end of the list: update the predecessor and current element to their respective next elements







                  share|improve this answer













                  for(x;y;z) ...; 


                  is equivalent to



                  x;
                  while(y)
                  ...;
                  z;



                  So



                   for ( ; tmp != null && !(tmp.info.equals(el));
                  pred = pred.next, tmp = tmp.next);


                  is equivalent to:



                  while(tmp != null && !(tmp.info.equals(el))) 
                  pred = pred.next, tmp = tmp.next;



                  In English, it would be something like




                  Until we find the element we're looking for, or the end of the list: update the predecessor and current element to their respective next elements








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 9 at 1:19









                  that other guythat other guy

                  75k886124




                  75k886124























                      1














                      The Java for loop has the form:



                      for (initialization; termination; increment) 
                      statement(s);



                      Your sample code is:



                      for ( ; tmp != null && !(tmp.info.equals(el));
                      pred = pred.next, tmp = tmp.next);


                      If we break it down, you can see there:



                      • is no initialization step

                      • two parts to the termination

                      • two (comma separated) statements in the increment step

                      In rough English:



                      • keep looping until tmp is null or tmp matches the element to be deleted, ie. iterate through the list until we reach the end or find a match

                      • each time through the loop, increment pred and tmp by pointing them to the next item





                      share|improve this answer

























                      • oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                        – Alan Kamali
                        Mar 9 at 1:50











                      • No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                        – dave
                        Mar 9 at 4:01











                      • what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                        – Alan Kamali
                        Mar 9 at 4:13











                      • Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                        – dave
                        Mar 10 at 5:23















                      1














                      The Java for loop has the form:



                      for (initialization; termination; increment) 
                      statement(s);



                      Your sample code is:



                      for ( ; tmp != null && !(tmp.info.equals(el));
                      pred = pred.next, tmp = tmp.next);


                      If we break it down, you can see there:



                      • is no initialization step

                      • two parts to the termination

                      • two (comma separated) statements in the increment step

                      In rough English:



                      • keep looping until tmp is null or tmp matches the element to be deleted, ie. iterate through the list until we reach the end or find a match

                      • each time through the loop, increment pred and tmp by pointing them to the next item





                      share|improve this answer

























                      • oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                        – Alan Kamali
                        Mar 9 at 1:50











                      • No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                        – dave
                        Mar 9 at 4:01











                      • what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                        – Alan Kamali
                        Mar 9 at 4:13











                      • Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                        – dave
                        Mar 10 at 5:23













                      1












                      1








                      1







                      The Java for loop has the form:



                      for (initialization; termination; increment) 
                      statement(s);



                      Your sample code is:



                      for ( ; tmp != null && !(tmp.info.equals(el));
                      pred = pred.next, tmp = tmp.next);


                      If we break it down, you can see there:



                      • is no initialization step

                      • two parts to the termination

                      • two (comma separated) statements in the increment step

                      In rough English:



                      • keep looping until tmp is null or tmp matches the element to be deleted, ie. iterate through the list until we reach the end or find a match

                      • each time through the loop, increment pred and tmp by pointing them to the next item





                      share|improve this answer















                      The Java for loop has the form:



                      for (initialization; termination; increment) 
                      statement(s);



                      Your sample code is:



                      for ( ; tmp != null && !(tmp.info.equals(el));
                      pred = pred.next, tmp = tmp.next);


                      If we break it down, you can see there:



                      • is no initialization step

                      • two parts to the termination

                      • two (comma separated) statements in the increment step

                      In rough English:



                      • keep looping until tmp is null or tmp matches the element to be deleted, ie. iterate through the list until we reach the end or find a match

                      • each time through the loop, increment pred and tmp by pointing them to the next item






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 9 at 3:59

























                      answered Mar 9 at 1:20









                      davedave

                      8,83853252




                      8,83853252












                      • oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                        – Alan Kamali
                        Mar 9 at 1:50











                      • No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                        – dave
                        Mar 9 at 4:01











                      • what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                        – Alan Kamali
                        Mar 9 at 4:13











                      • Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                        – dave
                        Mar 10 at 5:23

















                      • oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                        – Alan Kamali
                        Mar 9 at 1:50











                      • No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                        – dave
                        Mar 9 at 4:01











                      • what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                        – Alan Kamali
                        Mar 9 at 4:13











                      • Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                        – dave
                        Mar 10 at 5:23
















                      oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                      – Alan Kamali
                      Mar 9 at 1:50





                      oh i was really confused on how it skipped initialisation. didn't know that was even possible, hence why i was having trouble following the code! Thanks a lot for the explanation! I definitely have a lot to learn haha!

                      – Alan Kamali
                      Mar 9 at 1:50













                      No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                      – dave
                      Mar 9 at 4:01





                      No problem. Theoretically any of the three for loop header expressions can be empty. However it would be unusual for the termination or increment expressions to be omitted as you typically need these. I have seen the following used for an infinite loop though: for (;;) ...

                      – dave
                      Mar 9 at 4:01













                      what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                      – Alan Kamali
                      Mar 9 at 4:13





                      what would even be the point of an infinite loop? when would you want to use such a thing in real life?

                      – Alan Kamali
                      Mar 9 at 4:13













                      Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                      – dave
                      Mar 10 at 5:23





                      Infinite loops do have their uses, eg. an event handler for a GUI. Such a program basically runs forever (until you exit) and you check for user input every so often in the loop.

                      – dave
                      Mar 10 at 5:23











                      0














                      A for loop is made up of four parts: the initialization expression, the termination expression, the increment expression, and the body.



                      (There's also a for-each style loop which has different syntax, but that's not what we're talking about here.)



                      So to parse this apart:



                      • The initialization expression is empty (nothing before the first ;)

                      • The termination expression is tmp != null && !(tmp.info.equals(el)

                      • The increment expression is pred = pred.next, tmp = tmp.next

                      • The body is also empty (after the closing ) of the for expression, the next statement is just ;

                      In plain English:




                      As long as tmp is not null, but tmp.info is not our desired element el, continue moving pred and tmp to point to the successor elements in the linked list.




                      The termination condition of this loop is that either tmp is null (if el was not an element of the list at all), or pred points to the node before the node that had el as a value, and tmp points to the node that has el as a value.



                      Note that this code is written in a very terse style. This kind of style was common for low-level code 20+ years ago; nowadays when I see code like this it makes me think it was written by an old-timer.



                      I would probably write the same method like this instead:



                      public void delete(Object item) 
                      if (head == null)
                      // The list is empty; we have no work to do.
                      return;

                      if (head.info.equals(item))
                      // We're deleting the head of the list; just update our head reference.
                      head = head.next;
                      return;

                      SLLNode previous = head;
                      SLLNode current = head.next;
                      while (current != null)
                      if (current.info.equals(item))
                      // Update the list to skip the current node, then we're done.
                      previous.next = current.next;
                      return;

                      // Move to the next node in the list.
                      previous = current;
                      current = current.next;

                      // If we reached this point, the item was not found in this list.
                      // There's nothing to do, so we're done anyway.






                      share|improve this answer





























                        0














                        A for loop is made up of four parts: the initialization expression, the termination expression, the increment expression, and the body.



                        (There's also a for-each style loop which has different syntax, but that's not what we're talking about here.)



                        So to parse this apart:



                        • The initialization expression is empty (nothing before the first ;)

                        • The termination expression is tmp != null && !(tmp.info.equals(el)

                        • The increment expression is pred = pred.next, tmp = tmp.next

                        • The body is also empty (after the closing ) of the for expression, the next statement is just ;

                        In plain English:




                        As long as tmp is not null, but tmp.info is not our desired element el, continue moving pred and tmp to point to the successor elements in the linked list.




                        The termination condition of this loop is that either tmp is null (if el was not an element of the list at all), or pred points to the node before the node that had el as a value, and tmp points to the node that has el as a value.



                        Note that this code is written in a very terse style. This kind of style was common for low-level code 20+ years ago; nowadays when I see code like this it makes me think it was written by an old-timer.



                        I would probably write the same method like this instead:



                        public void delete(Object item) 
                        if (head == null)
                        // The list is empty; we have no work to do.
                        return;

                        if (head.info.equals(item))
                        // We're deleting the head of the list; just update our head reference.
                        head = head.next;
                        return;

                        SLLNode previous = head;
                        SLLNode current = head.next;
                        while (current != null)
                        if (current.info.equals(item))
                        // Update the list to skip the current node, then we're done.
                        previous.next = current.next;
                        return;

                        // Move to the next node in the list.
                        previous = current;
                        current = current.next;

                        // If we reached this point, the item was not found in this list.
                        // There's nothing to do, so we're done anyway.






                        share|improve this answer



























                          0












                          0








                          0







                          A for loop is made up of four parts: the initialization expression, the termination expression, the increment expression, and the body.



                          (There's also a for-each style loop which has different syntax, but that's not what we're talking about here.)



                          So to parse this apart:



                          • The initialization expression is empty (nothing before the first ;)

                          • The termination expression is tmp != null && !(tmp.info.equals(el)

                          • The increment expression is pred = pred.next, tmp = tmp.next

                          • The body is also empty (after the closing ) of the for expression, the next statement is just ;

                          In plain English:




                          As long as tmp is not null, but tmp.info is not our desired element el, continue moving pred and tmp to point to the successor elements in the linked list.




                          The termination condition of this loop is that either tmp is null (if el was not an element of the list at all), or pred points to the node before the node that had el as a value, and tmp points to the node that has el as a value.



                          Note that this code is written in a very terse style. This kind of style was common for low-level code 20+ years ago; nowadays when I see code like this it makes me think it was written by an old-timer.



                          I would probably write the same method like this instead:



                          public void delete(Object item) 
                          if (head == null)
                          // The list is empty; we have no work to do.
                          return;

                          if (head.info.equals(item))
                          // We're deleting the head of the list; just update our head reference.
                          head = head.next;
                          return;

                          SLLNode previous = head;
                          SLLNode current = head.next;
                          while (current != null)
                          if (current.info.equals(item))
                          // Update the list to skip the current node, then we're done.
                          previous.next = current.next;
                          return;

                          // Move to the next node in the list.
                          previous = current;
                          current = current.next;

                          // If we reached this point, the item was not found in this list.
                          // There's nothing to do, so we're done anyway.






                          share|improve this answer















                          A for loop is made up of four parts: the initialization expression, the termination expression, the increment expression, and the body.



                          (There's also a for-each style loop which has different syntax, but that's not what we're talking about here.)



                          So to parse this apart:



                          • The initialization expression is empty (nothing before the first ;)

                          • The termination expression is tmp != null && !(tmp.info.equals(el)

                          • The increment expression is pred = pred.next, tmp = tmp.next

                          • The body is also empty (after the closing ) of the for expression, the next statement is just ;

                          In plain English:




                          As long as tmp is not null, but tmp.info is not our desired element el, continue moving pred and tmp to point to the successor elements in the linked list.




                          The termination condition of this loop is that either tmp is null (if el was not an element of the list at all), or pred points to the node before the node that had el as a value, and tmp points to the node that has el as a value.



                          Note that this code is written in a very terse style. This kind of style was common for low-level code 20+ years ago; nowadays when I see code like this it makes me think it was written by an old-timer.



                          I would probably write the same method like this instead:



                          public void delete(Object item) 
                          if (head == null)
                          // The list is empty; we have no work to do.
                          return;

                          if (head.info.equals(item))
                          // We're deleting the head of the list; just update our head reference.
                          head = head.next;
                          return;

                          SLLNode previous = head;
                          SLLNode current = head.next;
                          while (current != null)
                          if (current.info.equals(item))
                          // Update the list to skip the current node, then we're done.
                          previous.next = current.next;
                          return;

                          // Move to the next node in the list.
                          previous = current;
                          current = current.next;

                          // If we reached this point, the item was not found in this list.
                          // There's nothing to do, so we're done anyway.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 9 at 1:34

























                          answered Mar 9 at 1:22









                          Daniel PrydenDaniel Pryden

                          47.3k975117




                          47.3k975117



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073043%2fhow-does-this-for-loop-translate-to-english%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme