wrong conversion of nested if

Issue #108 invalid
Former user created an issue

hello, I met to a little problem: the pascal expression is converted into javascript by wrong way

pascal code:

    if lTest > 0 then
      for i := 0 to 2 do
        if lVal * i mod 2 = 0 then
            lVal := lVal + i
    else 
      if lTest < 0 then
      begin
        for i := 0 to 2 do
          if lVal * i mod 2 = 1 then
          lVal := lVal + i
      end;

javascript code:

      if (lTest>0) {
         for(i$122=0;i$122<=2;i$122++) {
            if (lVal$1*i$122%2==0) {
               lVal$1 = lVal$1+i$122;
            } else if (lTest<0) {
               for(i$122=0;i$122<=2;i$122++) {
                  if (lVal$1*i$122%2==1) {
                     lVal$1 = lVal$1+i$122;
                  }
               }
            }
         }
      }

Comments (3)

  1. Christian Budde

    I'd say it is correct, but your indention cloaks a missing 'else'. I guess you wanted to write something like:

    if lTest > 0 then
      for i := 0 to 2 do
        if lVal * i mod 2 = 0 then
            lVal := lVal + i
        else 
    else 
      if lTest < 0 then
      begin
        for i := 0 to 2 do
          if lVal * i mod 2 = 1 then
          lVal := lVal + i
      end;
    
  2. Eric Grange repo owner

    Yes, I also think that the JS corresponds to the Pascal, but "else" matches the inner "if", while it was probably meant to match the outer one

  3. Log in to comment