# 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


## closed as off-topic by m_goldberg, corey979, MarcoB, happy fish, ubpdqnApr 5 '17 at 3:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, corey979, MarcoB, happy fish, ubpdqn
If this question can be reworded to fit the rules in the help center, please edit the question.

• 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.