return the other functions of the void main()

Jack Applegame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 9 05:57:24 PDT 2015


> I quite often have to write similar designs:
>
> -----
> import std.stdio;
>
> void main() {
>
> 	auto a = [ 1, 2, 3, 4, 5 ];
>
> 	foreach (e; a) {
> 		if (e == 4) {
> 			writeln("Yes");
> 			return;
> 		}
> 	}
> 	
> 	writeln("No");
> }
> -----
>
> But is not it easier to write :)
>
> import std.stdio;
>
> void main() {
>
> 	auto a = [ 1, 2, 3, 4, 5 ];
>
> 	foreach (e; a) {
> 		if (e == 4) {
> 			return writeln("Yes");
> 		}
> 	}
> 	
> 	writeln("No");
> }

import std.stdio;
import std.algorithm;
import std.array;

void main() {
   auto a = [ 1, 2, 3, 4, 5 ];
   writeln(a.find(4).empty ? "No" : "Yes");
}


More information about the Digitalmars-d-learn mailing list