Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37317 > unrolled thread
| Started by | groovee@cyberdude.com |
|---|---|
| First post | 2019-09-21 11:15 -0700 |
| Last post | 2019-09-22 18:49 +0200 |
| Articles | 12 — 5 participants |
Back to article view | Back to comp.lang.javascript
What does this line of code mean? groovee@cyberdude.com - 2019-09-21 11:15 -0700
Re: What does this line of code mean? Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-09-21 18:30 +0000
Re: What does this line of code mean? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-09-22 11:25 +0100
Re: What does this line of code mean? Julio Di Egidio <julio@diegidio.name> - 2019-09-22 04:53 -0700
Re: What does this line of code mean? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-09-22 15:40 +0100
Re: What does this line of code mean? "R.Wieser" <address@not.available> - 2019-09-22 19:01 +0200
Re: What does this line of code mean? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-09-23 11:13 +0100
Re: What does this line of code mean? "R.Wieser" <address@not.available> - 2019-09-23 14:15 +0200
Re: What does this line of code mean? groovee@cyberdude.com - 2019-09-25 12:20 -0700
Re: What does this line of code mean? "R.Wieser" <address@not.available> - 2019-09-22 15:39 +0200
Re: What does this line of code mean? Julio Di Egidio <julio@diegidio.name> - 2019-09-22 06:57 -0700
Re: What does this line of code mean? "R.Wieser" <address@not.available> - 2019-09-22 18:49 +0200
| From | groovee@cyberdude.com |
|---|---|
| Date | 2019-09-21 11:15 -0700 |
| Subject | What does this line of code mean? |
| Message-ID | <f27ce718-9b0b-4641-86f1-bfc079462875@googlegroups.com> |
My JS book was explaining Graphs, and in the code for "finding shortest paths using BFS", it had this line:
blah blah..
for (var v=toVertex; v!== fromVertex; v=shortestPathA.predecessors[v] {
path.push(v);
}
blah blah...
What is the "for" line doing? I'm especially not understanding the THIRD argument - I always thought the 3rd thing in a "for" HAD to be "something++" or "something--"?? Could someone please explain?
Thanx.
[toc] | [next] | [standalone]
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Date | 2019-09-21 18:30 +0000 |
| Message-ID | <slrnqocr2r.5c3.jon+usenet@sable.unequivocal.eu> |
| In reply to | #37317 |
On 2019-09-21, groovee@cyberdude.com <groovee@cyberdude.com> wrote:
> My JS book was explaining Graphs, and in the code for "finding shortest paths using BFS", it had this line:
>
> blah blah..
> for (var v=toVertex; v!== fromVertex; v=shortestPathA.predecessors[v] {
> path.push(v);
> }
> blah blah...
>
> What is the "for" line doing? I'm especially not understanding the
> THIRD argument - I always thought the 3rd thing in a "for" HAD to be
> "something++" or "something--"?? Could someone please explain?
No, the third argument (indeed all the arguments) can be any
expression. The first one is always evaluated once, the second one
is evaluated each time before the code inside the 'for' statement
is executed and causes the loop to immediately terminate if its
result is a false value, and the third one is executed each time
round the loop after the inner code has run.
So "for (a; b; c) { d }" is similar to: "a; while (b) { d; c }".
All of the expressions are optional, for example "for (;;) { ... }"
is a simple way of creating an infinite loop (although the loop can
of course be terminated by the code inside it executing a 'break').
As another example, you might walk along a linked list of items with
something like: "for (let item = listHead; item; item = item.next)".
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2019-09-22 11:25 +0100 |
| Message-ID | <vpieoepequgh08bsnrf6qg9g4r48eqfbnh@4ax.com> |
| In reply to | #37317 |
On Sat, 21 Sep 2019 11:15:24 -0700 (PDT), groovee@cyberdude.com wrote:
>My JS book was explaining Graphs, and in the code for "finding shortest paths using BFS", it had this line:
>
>blah blah..
>for (var v=toVertex; v!== fromVertex; v=shortestPathA.predecessors[v] {
> path.push(v);
>}
>blah blah...
>
>What is the "for" line doing? I'm especially not understanding the THIRD argument - I always thought the 3rd thing in a "for" HAD to be "something++" or "something--"?? Could someone please explain?
Unless you are doing something peculiar, the third term's job is to
move along. If v is a number then you add/subtract something. One is a
commonly needed amount; that can be done using ++/--.
If v is a graph node, then the third term moves v to the next node to
be processed. When the next node is the node you started from then
it's all done and the for loop exits.
John
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-09-22 04:53 -0700 |
| Message-ID | <b466aef9-f439-478f-9e8b-3968a1dc7c85@googlegroups.com> |
| In reply to | #37323 |
On Sunday, 22 September 2019 12:25:41 UTC+2, John G Harris wrote:
> On Sat, 21 Sep 2019 11:15:24 -0700 (PDT), groovee@cyberdude.com wrote:
>
> >My JS book was explaining Graphs, and in the code for "finding shortest paths using BFS", it had this line:
> >
> >blah blah..
> >for (var v=toVertex; v!== fromVertex; v=shortestPathA.predecessors[v] {
> > path.push(v);
> >}
> >blah blah...
> >
> >What is the "for" line doing? I'm especially not understanding the THIRD argument - I always thought the 3rd thing in a "for" HAD to be "something++" or "something--"?? Could someone please explain?
>
> Unless you are doing something peculiar, the third term's job is to
> move along. If v is a number then you add/subtract something. One is a
> commonly needed amount; that can be done using ++/--.
>
> If v is a graph node, then the third term moves v to the next node to
> be processed. When the next node is the node you started from then
> it's all done and the for loop exits.
>>No, the third argument (indeed all the arguments) can be any expression.<<
Not only the question was already answered and pretty decently so and you
just post over it, you piece of shit and resident spammer, you also and
always just write utterly retarded bullshit, you utterly stupid fuck.
*Plonk*
Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2019-09-22 15:40 +0100 |
| Message-ID | <nu1foe53ihg9as4v6hstd0hd80mob58935@4ax.com> |
| In reply to | #37325 |
On Sun, 22 Sep 2019 04:53:12 -0700 (PDT), Julio Di Egidio
<julio@diegidio.name> wrote:
>On Sunday, 22 September 2019 12:25:41 UTC+2, John G Harris wrote:
>> On Sat, 21 Sep 2019 11:15:24 -0700 (PDT), groovee@cyberdude.com wrote:
>>
>> >My JS book was explaining Graphs, and in the code for "finding shortest paths using BFS", it had this line:
>> >
>> >blah blah..
>> >for (var v=toVertex; v!== fromVertex; v=shortestPathA.predecessors[v] {
>> > path.push(v);
>> >}
>> >blah blah...
>> >
>> >What is the "for" line doing? I'm especially not understanding the THIRD argument - I always thought the 3rd thing in a "for" HAD to be "something++" or "something--"?? Could someone please explain?
>>
>> Unless you are doing something peculiar, the third term's job is to
>> move along. If v is a number then you add/subtract something. One is a
>> commonly needed amount; that can be done using ++/--.
>>
>> If v is a graph node, then the third term moves v to the next node to
>> be processed. When the next node is the node you started from then
>> it's all done and the for loop exits.
Where did this next quote line come from? It certainly isn't a quote
from the article I posted.
>>>No, the third argument (indeed all the arguments) can be any expression.<<
>Not only the question was already answered and pretty decently so
Jon said what a for statement does; I said why it does it. There's
nothing wrong with that.
Also, who said Jon's article arrived at my News Server in time for me
to see it before posting my reply?
>and you
>just post over it, you piece of shit and resident spammer,
"over" it?? Oh, now I see why you added a line from Jon's article. It
was to pretend that I was overwriting it. That sort of lie is bad for
the group.
>you also and
>always just write utterly retarded bullshit, you utterly stupid fuck.
If you seriously think that what I wrote is wrong then you've very
much misunderstood for statements.
Finally, please take your tablets. You know you really need them.
John
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-09-22 19:01 +0200 |
| Message-ID | <qm89e2$39o$1@gioia.aioe.org> |
| In reply to | #37330 |
John > Where did this next quote line come from? It certainly isn't a quote > from the article I posted. > >>>>No, the third argument (indeed all the arguments) can be any >>>>expression.<< Its from the first reply to your question from Jon Ribbens.. The extra brackets have been added by our "great teacher and overal nice guy" /s Julio, who, with his 20-20 vision (looking back when already knowing something), thought that one line should be enough to you as /the/ answer. So, he added some "**look here!**" markers - fully forgetting that those brackets also have a distinct function when quoting something someone else said. Or he just didn't care. Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2019-09-23 11:13 +0100 |
| Message-ID | <3k6hoe5add651cbq9c20o81aam5rvhjgl1@4ax.com> |
| In reply to | #37332 |
On Sun, 22 Sep 2019 19:01:42 +0200, "R.Wieser" <address@not.available> wrote: >John > >> Where did this next quote line come from? It certainly isn't a quote >> from the article I posted. >> >>>>>No, the third argument (indeed all the arguments) can be any >>>>>expression.<< > >Its from the first reply to your question from Jon Ribbens.. > >The extra brackets have been added by our "great teacher and overal nice >guy" /s Julio, who, with his 20-20 vision (looking back when already knowing >something), thought that one line should be enough to you as /the/ answer. >So, he added some "**look here!**" markers - fully forgetting that those >brackets also have a distinct function when quoting something someone else >said. Or he just didn't care. Maybe he doesn't realise that the way to do it is : On Sat, 21 Sep 2019 18:30:51 -0000 (UTC), Jon Ribbens <jon+usenet@unequivocal.eu> wrote: >No, the third argument (indeed all the arguments) can be any Oh dear! Have I committed the crime of supplementing what you wrote? John
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-09-23 14:15 +0200 |
| Message-ID | <qmad11$1f0e$1@gioia.aioe.org> |
| In reply to | #37341 |
John, > Maybe he doesn't realise that the way to do it is : [Snip] Well, that is up for grabs. I personally don't mind /how/ its done, as long as its clear where it came from. No extra info is needed as long as you can count the brackets and go back as many responses. But when quoting/referencing something out-of-sequence (or from another thread) than at least the (thread and) posters name as well as the date/time does certainly help to find it back. > Oh dear! Have I committed the crime of supplementing what you wrote? Whut??? Why would you think I would mind ? Are you mixing me up with someone else ? Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | groovee@cyberdude.com |
|---|---|
| Date | 2019-09-25 12:20 -0700 |
| Message-ID | <6891279f-76e3-4c28-b2ba-a2385546ad31@googlegroups.com> |
| In reply to | #37323 |
On Sunday, 22 September 2019 15:55:41 UTC+5:30, John G Harris wrote: > > Unless you are doing something peculiar, the third term's job is to > move along. If v is a number then you add/subtract something. One is a > commonly needed amount; that can be done using ++/--. > > If v is a graph node, then the third term moves v to the next node to > be processed. When the next node is the node you started from then > it's all done and the for loop exits. > > John Ah thanks for all the help guys :) Julio, I don't think people who sit around helping people for free on the internet qualify as "utterly stupid fucks".....know what I mean? YOU however, do. Instead of just sitting around "plonking" people (which I think you've been doing for YEARS now), why don't you just FUCK THE HELL OFF FROM HERE??
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-09-22 15:39 +0200 |
| Message-ID | <qm7tik$cpf$1@gioia.aioe.org> |
| In reply to | #37317 |
groovee, > I always thought the 3rd thing in a "for" HAD to be "something++" > or "something--" Both "something++" and or "something--" are just changing "something". In your described cases, by one. But you can write "something++" differently. Like "something += 1" or even "something = something + 1". All three wil work (try it!). And with any assignment you can put whole calculations at the right of the "=" (like "anything = anything / 2 + 1"), or even expressions which calls other functions and/or methods. Which is what happens in your case. Hope that helps. Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-09-22 06:57 -0700 |
| Message-ID | <cd7c77cd-28a1-4ea9-9296-b393b79a44bc@googlegroups.com> |
| In reply to | #37327 |
On Sunday, 22 September 2019 15:39:41 UTC+2, R.Wieser wrote: > groovee, > > > I always thought the 3rd thing in a "for" HAD to be "something++" > > or "something--" > > Both "something++" and or "something--" are just changing "something". In > your described cases, by one. > > But you can write "something++" differently. Like "something += 1" or even > "something = something + 1". All three wil work (try it!). > > And with any assignment you can put whole calculations at the right of the > "=" (like "anything = anything / 2 + 1"), or even expressions which calls > other functions and/or methods. Which is what happens in your case. > > Hope that helps. The question was already answered and pretty decently so, and you too just post over it, you other piece of shit and resident troll, just always vouching for doing the wrong thing, in your case the freedom to be a selfish retard and hero of your own time. Julio
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-09-22 18:49 +0200 |
| Message-ID | <qm88o6$1vuk$1@gioia.aioe.org> |
| In reply to | #37328 |
Julio, > The question was already answered and pretty decently so I'm sure it was. A few millions of times. Didn't see it in /this/ thread though, and you forgot to quote which message/thread you where/are referring to. As such your statement has zero worth to me. Sorry (not really, but thats what I'm supposed to say). > you other piece of shit and resident troll Ah yes, slinging abrasive shit around like a hippopottamus (its actually funny to see when that animal does it), and than complaining about other people hurting your tender soul - simply by disagreeing with you. As for "you other" ? You should keep a list, as I've seen you rant towards other people too - which, by the way, lowers the inpact of your animosity towards us quite a bit : do it to one person (once) and he might have deserved it. Do it to a list of people regulary and chances are that /you/ are the problem. Ever thought of that ? Nah, probably not. And by the way, your "*Plonk*" is /again/ broken. Remember that you told me - twice - that you would do it to me. Still, here you are, reading my posts and, worse, thinking that slinging shit will make you look some bigwig here in these newsgroups. It doesn't. Kiddo, for your sake I hope you're actually trolling. If you're not you've got a bit of a problem. Regards, Rudy Wieser
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web