JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a while Loop

Robert O'Toole
Robert O'Toole
3,690 Points

while(counter<???)

it seems that for some questions if i want the loop to run 28 times this works:

while(count<29)

then other times this works:

while(count<28)

why is that? im still making sure to put the count +=1 and var count=0

can someone plz explain this? the past few quizzes seem to give me different reasons why code isnt working and to my knowledge it seems rather inconsistent :/

KRIS NIKOLAISEN
KRIS NIKOLAISEN
Pro Student 51,749 Points

Can you provide complete code loop examples?

1 Answer

Because if you only put a greater than sign ">" or less than "<" sign, the number you provided will not be included. So if you write "count < 26" this will make it count to 26 but not including 26. On the other hand, if you add an equal sign like this "count <= 26" , this will include the 26. The count starts from zero, so this "count <= 26" will count 27 times because it includes the zero and the number 26. This "count < 26" will count it 26 times because it gets the zero but not including the 26. I hope this clears things up for you :)