0
About JavaScript loops
Explain the following statement from a loop codes: for (n=2; n<=8 ; n++) Anyone to please help me?
3 Answers
0
it means numbers from 2 to 8 (2,3,4,5,6,7,8) n=2 is starting point in loop , n<=8 ending point , and n++ is iteration , after 2 n will be 3 (n++, or 2++) , then 4,5,6,7,8 and it is your loop đ
0
for (n=2, n<=8, n++)
Statement 1.
n=2 // means you declare a number before your looping start.
Statement 2.
n<=8 // means you define a condition for your loop to run
Statement 3.
n++ //means that your n will increase once the condition in no. 2 returns true.
example:
for (n=2, n<=8, n++){
document.write("Hello /n")
}
Output would be like:
Hello //returns true, n=2
Hello //returns true, n=3
Hello //returns true, n=4
Hello //returns true, n=5
Hello //returns true, n=6
Hello //returns true, n=7
Hello //returns true, n=8 and it stop at 8 since your condition at 2nd statement is n<=8.
0
I still dont understand am trying too write the code but still it cant run
how should I write this code for (n=2; n<=8 ; n++)
Anyone to please help me?