Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

return

Part of KeywordsCategory

Description

Return exits a function

Example

/* Return exits a function. 
 * If it's not a void function return allows you to return a value. 
 */

import std.stdio;

void f1 () {
  writefln("Running f1...");
}

void f2 () { 
  bit itsAGoodIdea = true;

  writefln("Running f2...");
    
  if(itsAGoodIdea) {
    f1();
    return; 
  }

  writefln("Don't go there.");
}

void main () {
  f2();
  writefln("The end.");
}

Output

Running f2...
Running f1...
The end.