Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-10-13 14:25:52, last edited by Zumza (2015-10-14 14:32:29)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,658

For

So today I was writing a for statement and by mistake I type something like this:

for(int i = 0; i < n, i++) {//blabla}

Anyways it took me an nanosecond to see that i put ',' instead of ';'. But now I started wondering why for syntax is for(<expr>; <expr>; <expr>) <block> and is not for(<expr>, <expr>, <expr>) <block>
Well of course this might be just a simple language notation but lots of programming language use this syntax although.

So why do you think the creators left it as that?




One possible affirmation is this:

for(
x = 0;
x < 10;
x++
)

Everybody edits, but some edit more than others

Offline

#2 2015-10-13 18:50:24

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: For

Weeeeell... The notation you stated was the notation of calling a method.

I think that says enough.

Offline

#3 2015-10-13 20:36:49

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,658

Re: For

den3107 wrote:

Weeeeell... The notation you stated was the notation of calling a method.

I think that says enough.

Did you even read the OP? I pointed that already After all in both cases are parameters for for


Everybody edits, but some edit more than others

Offline

#4 2015-10-13 21:29:29

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: For

Zumza wrote:
den3107 wrote:

Weeeeell... The notation you stated was the notation of calling a method.

I think that says enough.

Did you even read the OP? I pointed that already After all in both cases are parameters for for

i dont think you get it.

void dostuff(int x,int y, int z)

dostuff(4,4,4);

for(i=0,i<7,i++)/////////////looks like a method

for(i=0;i<7;i++;)


if you can read this....good for you

Offline

#5 2015-10-13 21:50:40

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: For

Please note, the FOR doesn't look like a function call (like the while and suchnot) because of the space... "for (" as opposed to "Console.WriteLine("

Further, here's how I see it.
If we divide those into three parts,
The first part is compiled/ran once at the beginning. It's the initialization for the loop. it is a line of code
The second part is a condition. If you passed it (as is) to a function, you'd be passing a boolean variable. In this case, however, we treat it as a line of code (because we run it each time)
Naturally, the third part is the first, only it is run each time. Again, it acts as a line because passing i++ would just give a number, not a command.

also, s/o: here

Offline

Wooted by:

#6 2015-10-13 21:52:07, last edited by den3107 (2015-10-13 21:56:12)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: For

Zumza wrote:
den3107 wrote:

Weeeeell... The notation you stated was the notation of calling a method.

I think that says enough.

Did you even read the OP? I pointed that already After all in both cases are parameters for for

Just because they're parameters (even though there are very strange parameters (like i++)) doesn't mean it's a method.

If it were to be a method, it would mean it's possible to override that method and change it's behaviour. I did some googling, and personally couldn't find any way to change the behaviour of a for-loop (or any kind of loop/if-statement/etc.) programetically (obviously you could change the language completely, but then you're making your own language which is based off the language you edited).

So again, long story short: a for loop isn't a method, hence they were forced to use a different kind of separation character.

This is a personal observation though, and I have another idea, but I'll share it once anybody shows interest (too lazy). (See EDIT2)

EDIT1:

hummerz5 wrote:

Please note, the FOR doesn't look like a function call (like the while and suchnot) because of the space... "for (" as opposed to "Console.WriteLine("

That's a prefered way of writing, you can write both a "for(" without space, and a "method (" with space (I personally write for( without space due to my Java background).

EDIT2:
Basically what hummerz5 said, though I wouldn't formulated it differently (and am not entirely certain we mean the same thing).

Offline

Wooted by:

#7 2015-10-13 22:08:40

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: For

^Same
I was referring to the C# vs2010 ide
but hey you do you

Offline

#8 2015-10-13 22:52:26

Soubr
Member
Joined: 2015-02-18
Posts: 36

Re: For

what's the point of this topic?

Offline

Wooted by:

#9 2015-10-14 01:17:58

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: For

Soubr wrote:

what's the point of this topic?

As per the description, "If it can haz cod, put it in here.", it fits.

If you work on precedents, however, it seems certain programming-related discussion has actually been moved to the off-topic category.

But our in-house coders doesn't seem to frequent the coding forums

Offline

#10 2015-10-14 02:23:11

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: For

hummerz5 wrote:

"If it can haz cod, put it in here.", it fits

Not necessarily true. It HAS to be EE related.


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#11 2015-10-14 03:00:15

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: For

Xfrogman43 wrote:
hummerz5 wrote:

"If it can haz cod, put it in here.", it fits

Not necessarily true. It HAS to be EE related.

^this

can has cod is more of a reference to EE nubs asking for the code than an actual description of the subforum. Probably wasn't the smartest thing to put as the description but eh.


"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto

Offline

Wooted by:

#12 2015-10-14 14:24:44, last edited by Zumza (2015-10-14 14:30:08)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,658

Re: For

You could thin on for like a method with an outside delegate.

//In an C like pseudocode
void for(<expression1>, <expression2>, <expression3>, <instruction block>) {
       execute(<expresion1>);
       loop: 
            if(!<expresion2>) return;
            execute(<instruction block>);
            execute(<expresion3>);
       goto loop;
}


I think they did it because they've considered the parameters instructions and because every instruction ends with an ";" they decided to do it as that.
And how den3107 also pointed out:

den3107 wrote:

So again, long story short: a for loop isn't a method, hence they were forced to use a different kind of separation character.


Everybody edits, but some edit more than others

Offline

Zumza1444829084549441

Board footer

Powered by FluxBB

[ Started around 1738976139.9698 - Generated in 0.063 seconds, 10 queries executed - Memory usage: 1.61 MiB (Peak: 1.79 MiB) ]