# If clause gives back 2 different result [closed]

I am writing a simple if clause, but keep getting wrong answers, so I ended up writing 2 almost the same if clauses, one giving back correct answer, and the other giving back wrong answer. Can't figure out the problem.

InsertIndex2[x_, list_] :=
Module[{length, compareResult, middleIndex, newList, newResult,
whichResult},
length = Length[list];
middleIndex = Floor[(length + 1)/2]；
#Print[middleIndex];
Print["length=", length];
If [length == 0,  1, 2]]


Input:

 c = {}
d = InsertIndex2[1, c]


Output:

length = 0
0


f = Module[{a}, a = 0; If[a == 0, 1, 2]]

input:

e=f


output:

1

• you have a problem with the semicolon after middleIndex. it does not look like a semicolon. – Ali Hashmi Apr 3 '17 at 15:47
• Also, what is #Print intended to be? – Bob Hanlon Apr 3 '17 at 15:54
• @bob a comment, apparently. – LLlAMnYP Apr 3 '17 at 17:25

If I remove the syntax errors and irrelevancies from your code

InsertIndex2[x_, list_] :=
Module[{length, middleIndex},
length = Length[list];
middleIndex = Floor[(length + 1)/2];
Print[middleIndex];
Print["length=", length];
If[length == 0, 1, 2]]


then

InsertIndex2[1, {}]


gives

which is exactly what you wanted.