I want the while loop to stop after the `loop_e' > `total_e' the first time it happens (when the foreach loop loops over trunk). However, the while loop only stops executing after all the variables in the foreach loop have been looped over.
Code:
sysuse auto, clear local total_e = 1e-2 local loop_e = 1 while `loop_e' > `total_e' { foreach var in trunk weight length turn { di "`var'" local loop_e = 1e-6 } }
0 Response to Nesting foreach loops within a while loop
Post a Comment