02.12.2011, 11:40
pawn Код:
new decide = random(2);
if(decide == 0);
{
return EVENT_TEAM_RED;
}
if(decide == 1);
{
return EVENT_TEAM_BLUE;
}
if(decide == 0); << error:Empty Statement
if(decide == 1); << error:Empty Statement
Why?
new decide = random(2);
if(decide == 0);
{
return EVENT_TEAM_RED;
}
if(decide == 1);
{
return EVENT_TEAM_BLUE;
}
// Your_Callback()
{
// Code(Optional. If you have)
new
decide = random(2);
switch(decide) {
case 0: {
return EVENT_TEAM_RED;
}
case 1: {
return EVENT_TEAM_BLUE;
}
}
// Rest
return 1;
}
That's not inefficient code - it compiles to EXACTLY the same thing as if the braces had been ommitted, and is (IMHO) much clearer to read than something all squashed together (as you wrote).
|
it compiles to EXACTLY the same thing as if the braces had been ommitted, and is (IMHO) much clearer to read than something all squashed together (as you wrote).
#define while2(%0=%1;%2) %0=%1; while(%2)
main()
{
while2(new i=100; i--)
{
printf("%d",i);
}
}
#define while2(%0=%1;%2) %0=%1; while(%2)
main()
{
while2(new i=100; i--) printf("%d",i);
}
new
decide = random(2);
switch(decide) {
case 0: return EVENT_TEAM_RED;
case 1: return EVENT_TEAM_BLUE;
}
new decide = random(2);
switch(decide)
{
case 0: return EVENT_TEAM_RED;
case 1: return EVENT_TEAM_BLUE;
}
Originally Posted by ******
That is the code I was referring to as "squashed".
|
new decide = random(2);
if(decide == 0) return EVENT_TEAM_RED;
else if(decide == 1) return EVENT_TEAM_BLUE;
new decide = random(2);
if(decide == 0)
{
return EVENT_TEAM_RED;
}
else if(decide == 1)
{
return EVENT_TEAM_BLUE;
}
Originally Posted by ******
If you are arguing that grouping single statements as compound statements is easier to read (as your posts seem to indicate, though I'm not too clear on what you're trying to say) then I really do disagree, but you're free to do it that way - I was just pointing out that it's not a code optimisation issue, just a layout issue.
|