7 Replies Latest reply: Oct 30, 2012 8:16 AM by TPD-Opitz RSS

    help using while and get

    968533
      how do i use a while to check if something is not empty and how do i GET an arc from what i checked if it was empty.

      Edited by: 965530 on 15-Oct-2012 8:33 PM
        • 1. Re: help using while and get
          Kayaman
          You don't use while to check if something is empty. You use while to keep doing something while a condition is true.
          The latter part of your question isn't clear. What's "GETting an arc"?
          • 2. Re: help using while and get
            RMishra
            suppose you have like String str="";
            then use if() to check empty like : if(str.equals(""){ System.out.print("empty"); }

            -RMishra
            • 3. Re: help using while and get
              TPD-Opitz
              RMishra wrote:
              then use if() to check empty like : if(str.equals(""){ System.out.print("empty"); }
              The better check would be
              if("".equals(str){ System.out.print("empty"); }
              just in case <tt>str</tt> is null...

              bye
              TPD
              • 4. Re: help using while and get
                968533
                while(toDoArcs.size() < 0);
                          {
                                              
                          Arc a = toDoArcs.remove(0);
                                              
                               a.getVariable();


                was it
                • 5. Re: help using while and get
                  rp0428
                  >
                  while(toDoArcs.size() < 0);
                  >
                  You can't get something if there isn't anything there. If size is < 1 there isn't anything there.
                  • 6. Re: help using while and get
                    EJP
                    965530 wrote:
                    while(toDoArcs.size() < 0);
                              {
                                                  
                              Arc a = toDoArcs.remove(0);
                                                  
                                   a.getVariable();


                    was it
                    No it wasn't. The block executes once unconditionally because of the spurious ';' after the 'while". When you fix that, it will never execute, because the condition is wrong. A size cannot be negative.
                    • 7. Re: help using while and get
                      TPD-Opitz
                      965530 wrote:
                      while(toDoArcs.size() < 0);
                      Pretending that toDoArcs is a List&lt;Arc&gt; the better way of looping over the content of this list is:
                      for (Arc arc : toDoArcs){
                        // do something with the arc
                      }
                      bye
                      TPD