Is it possible to exit a contract?

Simen Kjærås simen.kjaras at gmail.com
Thu Mar 22 17:18:54 UTC 2018


On Thursday, 22 March 2018 at 13:16:00 UTC, berni wrote:
> Part of my code looks like this:
>
>> out (result)
>> {
>>   if (result==true)
>>   {
>>     lots of assertions...
>>   }
>> }
>
> I would prefer an early exit like:
>
>> out (result)
>> {
>>   if (result==false) return;
>> 
>>   lots of assertions...
>> }
>
> Is this possible somehow (return and break don't do the 
> job...). The only thing I found is using goto, which I prefer 
> over that gigantic if-block, but maybe there is something 
> better, I don't know of?

It's a hack, but it works:

void bar()
in {(){
     return;
     assert(false);
}();}
body
{
}

unittest {
     bar();
}

--
   Simen


More information about the Digitalmars-d-learn mailing list