generate correct js code for code that loop appear after branch