Zerivo Posted September 4, 2017 Share Posted September 4, 2017 (edited) Quote <head><script type="text/javascript"> function AddInfo() { var text="";var txt=""; var IF=""; var NL=1;var NR=1; for (NL = 1; NL < 3; NL++){ for (NR = 1; NR < 3; NR++){ if (NR==1) {CR=["T1","C1"]} else if (NR==2) {CR=["T2","C2"]} else if (NR==3) {CR=["T3","C3"]} text += "L"+NL+': '+CR[0]+'&'+CR[1]+"---"; } txt += text+"<br>"; } document.getElementById("Test").innerHTML = txt; } </script></head> <body onload="AddInfo()"> <div id="Test"></div> </body> filer : loop in loop fail.html I was try make loop in loop with array. it should be like: L1: T1&C1---L1: T2&C2---L1: T3&C3--- L2: T1&C1---L2: T2&C2---L2: T3&C3--- L3: T1&C1---L3: T2&C2---L3: T3&C3--- But I got other than that i thought, so what did i wrong? Edited September 4, 2017 by Zerivo Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 (edited) You are duplicating the last output, and you require break on last loop where nr == 3. function AddInfo() { var text = ""; var txt = ""; // var IF = ""; var NL = 1; var NR = 1; for (NL = 1; NL <= 3; NL++) { for (NR = 1; NR <= 3; NR++) { if (NR == 1) { CR = ["T1", "C1"] } else if (NR == 2) { CR = ["T2", "C2"] } else if (NR == 3) { CR = ["T3", "C3"] } text += "L" + NL + ': ' + CR[0] + '&' + CR[1] + "---"; if (NR == 3) { text += "<br>" } } } txt = text + ""; document.getElementById("Test").innerHTML = txt; } Also it will never loop through 3rd, because its restricted to looping (< 3) to 2 only. Edited September 4, 2017 by dsonesuk Link to comment Share on other sites More sharing options...
Zerivo Posted September 11, 2017 Author Share Posted September 11, 2017 oh i see. thank! ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now