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.
Pages: 1
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
Weeeeell... The notation you stated was the notation of calling a method.
I think that says enough.
Offline
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
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
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
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:
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
what's the point of this topic?
Offline
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
"If it can haz cod, put it in here.", it fits
Not necessarily true. It HAS to be EE related.
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
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
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:
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
Pages: 1
[ Started around 1738984802.2427 - Generated in 0.199 seconds, 12 queries executed - Memory usage: 1.61 MiB (Peak: 1.79 MiB) ]