#is this a good way to explain a loop??

43 messages ยท Page 1 of 1 (latest)

vast dust
#

i cant find any tutorials explaining it

remote lava
#

not really?

hushed whale
#

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

potent kestrel
#

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.

oblique seal
#

Documented code is basically out of date as soon as it's written. And is just as untrustworthy ๐Ÿ™ƒ

vast dust
#

whats this meant to mean?

remote lava
#

which part isn't clear? did you read the links above?

vast dust
#

yes i understand those

vast dust
#

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

remote lava
#

"bit"? no...

vast dust
#

obj?

remote lava
#

no. wtf? please read through the entire javascript.info tutorial. start from the beginning

vast dust
#

whats alert?

remote lava
#

you're ridiculous...

vast dust
#

im reading it rn

#

i sent the message before i realised i could just check on js info

#

xd

remote lava
#

if you ask a question before checking MDN or JS.info, you're doing it wrong.

vast dust
#

oh alert is only for the browser

#

would this be better?

remote lava
#

no

vast dust
#

whats wrong with my definition?

remote lava
#

a lot

#

who are you trying to explain this to?

vast dust
#

myself

#

im trying to simplify loops so it can be readable for me

#

cuz i never done loops before

remote lava
#

so you read through the tutorial (which explains it very well) and then try to explain it a different way (which makes no sense)?

vast dust
#

im trying to reword the tutorial to something simpler

remote lava
#
  • WTF is "I think it pastes everything"?
  • yes, i starts at 0.
  • 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.length literally means "if i is less than the length of the array blogs"
  • no, i++ does not "make it execute"... i++ is what happens after each iteration of the loop. i is simply incremented, then everything starts all over.
vast dust
remote lava
vast dust
#

is it like it goes to the next position in an array?

remote lava
#

no. i is variable storing a number. you increment that number. you really need to go read the basics.