title: How to reuse the variable used for for loop first level inside for loop second level in nested for loop
body: <p>Someone can tell me how can I reuse rootOpt object inside of my forEach. Is there any way to reuse this variable? I have the following message "Can not resolve symbol rootOpt" when I write rootOpt.getChildOptions() inside my forEach. Please find below what I did:
  I have tried to rewrite the for loop below by using stream. Thank you</p>
  
  <pre><code>opts.stream()
                  .flatMap(rootOpt -&gt; rootOpt.getChildOptions().stream())
                  .forEach(subOpt -&gt; {
                      if (subOpt.getOptLogic() != null &amp;&amp; subOpt.getOptLogic().getCant() != null &amp;&amp; !"".equals(subOpt.getOptLogic().getCant())) {
                          String[] oldCHs = subOpt.getOptLogic().getCant().split("( )");
                          OptionList samePriceSibs = getSamePriceS(rootOpt.getChildOptions(), subOpt);
                          for (String ch : oldCHs) {
                              Option chRootOpt = childOptCodeToParentOptMap.get(ch.toUpperCase());
                              if (chRootOpt != null) {
                                  if (!DoesVariableOptionsCompletelyExcludeOther(samePriceSibs, chRootOpt.getChildOptions())) {
                                      List&lt;OptionList&gt; tmp = new ArrayList&lt;OptionList&gt;();
                                      tmp.add(samePriceSibs);
                                      tmp.add(chRootOpt.getChildOptions());
                                      optionsPairsToRemoveCHs.add(tmp);
                                  }
                              }
                          }
                      }
                  });
  
              for (Option rootOpt : opts) {
                  for (Option subOpt : rootOpt.getChildOptions()) {
                      if (subOpt.getOptLogic() != null &amp;&amp; subOpt.getOptLogic().getCant() != null &amp;&amp; !"".equals(subOpt.getOptLogic().getCant())) {
                          String[] oldCHs = subOpt.getOptLogic().getCant().split("( )");
                          OptionList samePriceSibs = getSamePriceS(rootOpt.getChildOptions(), subOpt);
                          for (String ch : oldCHs) {
                              Option chRootOpt = childOptCodeToParentOptMap.get(ch.toUpperCase());
                              if (chRootOpt != null) {
                                  if (!DoesVariableOptionsCompletelyExcludeOther(samePriceSibs, chRootOpt.getChildOptions())) {
                                      List&lt;OptionList&gt; tmp = new ArrayList&lt;OptionList&gt;();
                                      tmp.add(samePriceSibs);
                                      tmp.add(chRootOpt.getChildOptions());
                                      optionsPairsToRemoveCHs.add(tmp);
                                  }
                              }
                          }
                      }
                  }
              }
  </code></pre>