Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread If then else compilation quirk
Mon, Aug 27 2012 11:32 PMPermanent Link

Frederick Chin

In Delphi, the following code syntax is logical and valid:-

if <something true> then
else
   <do something>;

In EWB, compilation stops with a:-

Expected ; but instead found <do something>

To get around it, I have to code it as:-

if <something false> then
  <do something>;

Is this a bug?

Frederick
Tue, Aug 28 2012 9:49 AMPermanent Link

Raul

Team Elevate Team Elevate

EWB if syntax is defined as

if <Boolean Expression> then
   <Code Block>
[else if <Boolean Expression>
   <Code Block>]
[else
   <Code Block>];

so it's not a bug.

Personally i don't consider the syntax you're asking about logical and
makes code less readable/understandable.

You can either use what you proposed use the

if not <something true> then
  <do something>;

Raul


On 8/27/2012 11:32 PM, Frederick Chin wrote:
> In Delphi, the following code syntax is logical and valid:-
>
> if <something true> then
> else
>      <do something>;
>
> In EWB, compilation stops with a:-
>
> Expected ; but instead found <do something>
>
> To get around it, I have to code it as:-
>
> if <something false> then
>     <do something>;
>
> Is this a bug?
>
> Frederick
>
Tue, Aug 28 2012 11:45 AMPermanent Link

Frederick Chin

/*
so it's not a bug.
*/

I wouldn't consider it a bug but it sure works differently from all the programming languages I have used. It sorts of trips you. Besides, EWB is supposed to be object pascal compatible.

/*
Personally i don't consider the syntax you're asking about logical and
makes code less readable/understandable.

You can either use what you proposed use the

if not <something true> then
  <do something>;
*/

Consider the following test condition:-

if (condition1) and (condition2) and (not condition3) then
else
   <do something>

compared with:-

if (not condition1) and (not condition2) and (condition3) then
   <do something>

Either syntax is correct but for me, doing nothing when all tests are true while doing something when ANY test is false is more logical than testing for false tests. I discovered early on that testing for positives was much easier than trying to wrap your head on negatives.

Frederick
Tue, Aug 28 2012 12:32 PMPermanent Link

Raul

Team Elevate Team Elevate


I'd use instead  :

if not (condition1 and condition2) and (condition3) then
      <do something>

but it's a personal choice

The dangling else visually looks like a bug ever time i glance at it so
in our team we don't use it.

Raul


On 8/28/2012 11:45 AM, Frederick Chin wrote:
> /*
> so it's not a bug.
> */
>
> I wouldn't consider it a bug but it sure works differently from all the programming languages I have used. It sorts of trips you. Besides, EWB is supposed to be object pascal compatible.
>
> /*
> Personally i don't consider the syntax you're asking about logical and
> makes code less readable/understandable.
>
> You can either use what you proposed use the
>
> if not <something true> then
>     <do something>;
> */
>
> Consider the following test condition:-
>
> if (condition1) and (condition2) and (not condition3) then
> else
>      <do something>
>
> compared with:-
>
> if (not condition1) and (not condition2) and (condition3) then
>      <do something>
>
> Either syntax is correct but for me, doing nothing when all tests are true while doing something when ANY test is false is more logical than testing for false tests. I discovered early on that testing for positives was much easier than trying to wrap your head on negatives.
>
> Frederick
>
Tue, Aug 28 2012 12:35 PMPermanent Link

John Hay

Frederick,

Following the syntax described by Raul does the following work?

if <something true> then
begin end //empty code block
else
   <do something>;

John

Tue, Aug 28 2012 9:55 PMPermanent Link

Frederick Chin

John,

/*
Following the syntax described by Raul does the following work?

if <something true> then
begin end //empty code block
else
   <do something>;
*/

Yes, it does.

Frederick
Image