Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D exit statement

Tags:

exit

d

Does D have an exit statement, similar to the one in java, python, c/c++. Which will (big shocker) exit execution of the program? Something like exit();

like image 772
alexmherrmann Avatar asked Aug 17 '11 21:08

alexmherrmann


People also ask

What do you mean by exit statement?

The EXIT statement exits the current iteration of a loop, either conditionally or unconditionally, and transfers control to the end of either the current loop or an enclosing labeled loop. Restriction on EXIT Statement. An EXIT statement must be inside a LOOP statement.

What is sub exit statement?

The Sub declaration is used to mark the beginning of a subroutine in the program code. The Exit Sub statement specifies the condition under which the program should exit the subroutine. The EndSub statement is placed after the last instruction in the subroutine code to mark the end of the subroutine.

What is exit loop in C?

break command (C and C++)The break command allows you to terminate and exit a loop (that is, do , for , and while ) or switch command from any point other than the logical end. You can place a break command only in the body of a looping command or in the body of a switch command.


1 Answers

If you want exit, then use C's exit function.

import core.stdc.stdlib;

void main()
{
    exit(-1);
}

I'm not quite sure how that affects the D runtime and whatnot though. It might be that stuff doesn't get cleaned up like you'd normally want, or it might be just fine. I wouldn't really advise using it in general though, since there are usually better ways to handle exiting a program. But the declaration for the C function is in druntime, so it's easy to use it if you want it.

like image 61
Jonathan M Davis Avatar answered Sep 30 '22 13:09

Jonathan M Davis