NOTE: fixed formatting for easier reading
good tutorial that lays out the rules of MEL syntax?
pretty much looks like shell scripting, its defined in the manual, but the short path since you already know programming concepts can be found here:
MEL for programmers (excerpt form maya manual, hit f1 to access it)
Im not sure you need all that code tough It looks awfully a lot like a job for not using the nestled ifs but the code is so confusingly written that its hard to see. Some pointers about style tough for example why on earth would anybody write:
rem = x+90;
convert1 = (90+rem)*-1;
Its easier to read if you write:
rem = x+90;
convert1 = -1*(x+180);
So that is what you should write
PS: plot rem and convert1 and youll see how it all has a much easier interpretation except for the -360 - -270 which is just weird for the remainder resuilt... possible bug?