#is this a good way to explain a loop??
43 messages ยท Page 1 of 1 (latest)
not really?
suggest you read through this amazing tutorial: https://javascript.info/
You are documenting what the code itself already tells you. Document what is going on conceptually "loop through all documents", "iterate through the returned rows", etc.
Or, if you're actually confused about how loops work in general, follow the links above
I'd even go one step further and say write your code in a way that makes these comments superfluous. You can do that by naming functions and variables properly and by breaking your code down into meaningful units.
Comments are best if they explain not what you're doing, but why. So use them sparingly and reserve them for clearing up why you had to do things in a certain way if it isn't clear from reading the code.
Documented code is basically out of date as soon as it's written. And is just as untrustworthy ๐
whats this meant to mean?
which part isn't clear? did you read the links above?
yes i understand those
im reading this rn
for loops specifically
i think i < 3 means it should end at the 3rd 'bit'
or is that not a good way to explain it
"bit"? no...
obj?
no. wtf? please read through the entire javascript.info tutorial. start from the beginning
https://javascript.info/comparison (but for the 3rd time, read the whole thing!)
whats alert?
you're ridiculous...
im reading it rn
i sent the message before i realised i could just check on js info
xd
no
whats wrong with my definition?
myself
im trying to simplify loops so it can be readable for me
cuz i never done loops before
so you read through the tutorial (which explains it very well) and then try to explain it a different way (which makes no sense)?
im trying to reword the tutorial to something simpler
- WTF is "I think it pastes everything"?
- yes,
istarts at0. - no, the loop does not automatically "execute once upon entering loop". this doesn't really make sense at all, but the loop only executes if the condition (
i < blogs.length) is true. if that condition is false, the loop will be skipped entirely. - "end of the blog section" is also unclear.
i < blogs.lengthliterally means "ifiis less than the length of the arrayblogs" - no,
i++does not "make it execute"...i++is what happens after each iteration of the loop.iis simply incremented, then everything starts all over.
the pastes everything i removed dw ๐ญ that was from ages ago
if it's not clear between JS.info and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for, I'm not sure what to suggest.
what is the last poin meant to mean. 'i++ is what happens after each iteration of the loop'
is it like it goes to the next position in an array?
no. i is variable storing a number. you increment that number. you really need to go read the basics.