- #1
SlurrerOfSpeech
- 141
- 11
I'll give you an example.
Let's say I have a snippet of code like
(which is a real snippet of code I have).
One might alternatively write it like
The main argument I can see for the first way is
"The variable c is only used in the while loop and therefore should be defined there as best practice."
The main argument I can see for the second way is
"It's equiavlent and more efficient because you don't have to initialize c during every iteration of the while loop."
What are your thoughts?
Let's say I have a snippet of code like
Code:
while(*s2)
{
char* c = s1;
while(*c++==*s2++);
if(!*c)
{
flag=true;
break;
}
else
{
flag=false;
}
}
(which is a real snippet of code I have).
One might alternatively write it like
Code:
char* c;
while(*s2)
{
c = s1;
while(*c++==*s2++);
if(!*c)
{
flag=true;
break;
}
else
{
flag=false;
}
}
The main argument I can see for the first way is
"The variable c is only used in the while loop and therefore should be defined there as best practice."
The main argument I can see for the second way is
"It's equiavlent and more efficient because you don't have to initialize c during every iteration of the while loop."
What are your thoughts?
Last edited by a moderator: