Foreach, return not exist the function.

Zaher Dirkey via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 11 12:25:43 PST 2015


First time i used foreach with opApply in my classed, and i got 
this strange behavior.

return e, not exit the function "findClass"
i tried to reproduce it, but it is worked in reproduce example.
but you can read it and read the result of writeln.
I still feel it is my eyes or a small mistake.

---------------------
SrdController findClass(const ClassInfo controllerClass)
{
	foreach(e; this) {
		if (e.classinfo.name == controllerClass.name) {
			writeln("we found " ~ e.classinfo.name);
			return e;
		}
	}
	writeln("not found ");
	return null;
}

results
------------------

sard.parsers.SrdControllers.add(sard.parsers.SrdControllerNormal)
sard.parsers.SrdControllers.add(sard.parsers.SrdControllerDefines)
we found sard.parsers.SrdControllerNormal
not found

reproduce example here
http://dpaste.dzfl.pl/13fb453d0b1e


it is part for opensource code here
https://github.com/parmaja/sard/blob/master/src/sard/parsers.d#L222


More information about the Digitalmars-d mailing list