title: Alternative to nested loops
body: <p>I wrote these method for my program and i felt that it is hard to read as there are too many loops, is there any other alternative to this code to make it look cleaner and easier to read</p>
  
  <pre><code>public static void printRoutingTable(Map &lt;Node, List&lt;Edge&gt;&gt; adj, Node Root)
  {
      for (Node thisNode : adj.keySet())
      {   
          Node currentNode = thisNode;
          String nextHop;             
          if(currentNode.getParent() != null){
              do{
                  if(currentNode.getParent() != Root){
                      currentNode = currentNode.getParent();
                      nextHop =  currentNode.getAddr();
                  }
                  else{
                     nextHop = currentNode.getAddr() ;
                  }       
              }
              while(currentNode.getParent() != Root);
          }
          else
          {
              nextHop = ""+currentNode.getAddr();
          }
          nextHop = nextHop.trim();
      }
  }
  </code></pre>