digitalmars.D.learn - Is it possible to exit a contract?
- berni (6/19) Mar 22 2018 Is this possible somehow (return and break don't do the job...).
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/26) Mar 22 2018 Never thought of it before. :) I would put all that code into a function...
- berni (5/7) Mar 22 2018 I rejected this, because I've got an unease feeling using extra
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (15/34) Mar 22 2018 It's a hack, but it works:
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?
Mar 22 2018
On 03/22/2018 06:16 AM, berni wrote:Part of my code looks like this:Never thought of it before. :) I would put all that code into a function and call from the out block. Aliout (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?
Mar 22 2018
On Thursday, 22 March 2018 at 16:22:04 UTC, Ali Çehreli wrote:Never thought of it before. :) I would put all that code into a function and call from the out block.I rejected this, because I've got an unease feeling using extra functions in contract programming. Can't tell, where this feeling comes from; maybe just because I've too few experience with contract programming...
Mar 22 2018
On Thursday, 22 March 2018 at 13:16:00 UTC, berni wrote:Part of my code looks like this:It's a hack, but it works: void bar() in {(){ return; assert(false); }();} body { } unittest { bar(); } -- Simenout (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?
Mar 22 2018