Semicolon can be left out after do-while
Steven Schveighoffer
schveiguy at yahoo.com
Wed Apr 13 07:13:27 PDT 2011
On Wed, 13 Apr 2011 09:44:54 -0400, Emil Madsen <sovende at gmail.com> wrote:
> On 13 April 2011 14:36, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>>
>> I know that if(xyz); is not *ever* what I meant, but in C it compiles.
>> However, in D, it tells me I shouldn't do that. What results is less
>> bugs
>> because I can't make that mistake without the compiler complaining.
>>
> Does D throw an error at; if(expression && expression)*; *or only at
> if(expression);
> Because you could actually use the first one, alike this:
> <code>
> #include <stdio.h>
>
> bool test()
> {
> printf("test\n");
> return false;
> }
>
> bool test2()
> {
> printf("test2\n");
> return true;
> }
>
> int main()
> {
> if(test() && test2());
> }
> </code>
> Output = "test"
> if test returns true, then: Output = "test" + "test2"
>
> Simply because its conditional, and if the first one fails, why bother
> evaluating the rest?
if(condition1 && condition2); is an error.
However, an expression can be a statement:
condition1 && condition2;
Note, you can get around the limitation if that *really is* what you meant
by doing:
if(expression) {}
An if statement is hard to justify for this, but I can see a while or for
loop making sense here.
-Steve
More information about the Digitalmars-d-learn
mailing list