If und If-Else?
-
Nabend zusammen
Ich habe hier mal 2 Blöcke mit Ifs zusammengeschustert, die nach meinem Empfinden equivalent sind.
if(A > B) { if(A > C) max = 1; else max = 3; } else { if(B > C) max = 2; else max = 3; } if(A > B) if(A > C) max=1; if(B > A) if(B > C) max=2; if(C > A) if(C > B) max=3;
Problem ist nur, sie sind's nicht. Aber auch nach zehnmaligem hinsehen weiss ich nicht woran es liegt.
Jemand nen Tipp für mich?
-
Im unteren Fall kann es passieren, dass max nicht zugewiesen wird, wenn zwei Werte gleich sind. Sind alle drei gleich, ist es sogar sicher.