Options

FOR..TO loop with decimal start/end value

TalinaTalina Member Posts: 8
Hi all,
Does anybody can tell me why the next code shows 4 messages with values
10,1 11,1 12,1 and 13,1 but not only three first ones :shock:

FOR decim := 10.1 TO 12.2 DO
MESSAGE('%1',decim);

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,090
    Decimals is not the datatype one uses with FOR-TO.
    It is used with datatypes with exactly defined types like integer,option and date.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    garakgarak Member Posts: 3,263
    Because navision use intern step 1.

    The code

    for i := 0.1 to 0.6 step 0.1 do begin
    ...
    end;

    doesn't know navision (step) :(

    But it knows "downto" :D , but also only with step 1 :(

    Regards
    Do you make it right, it works too!
  • Options
    TalinaTalina Member Posts: 8
    kriki wrote:
    Decimals is not the datatype one uses with FOR-TO.
    It is used with datatypes with exactly defined types like integer,option and date.

    kriki!
    May be you are right.
    But Development 1 sais this 'variable must be a variable of type Boolean, Date, Time or any numeric type'. Nothing about integer values. Only numeric
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Talina wrote:
    kriki wrote:
    Decimals is not the datatype one uses with FOR-TO.
    It is used with datatypes with exactly defined types like integer,option and date.

    kriki!
    May be you are right.
    But Development 1 sais this 'variable must be a variable of type Boolean, Date, Time or any numeric type'. Nothing about integer values. Only numeric
    This means it CAN be used, but it is not always adviced.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    TalinaTalina Member Posts: 8
    Many manuals for beginners have such inaccuracies.
    How we can pass exams well :?
    Never believe!
    Allways check!
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Talina wrote:
    Hi all,
    Does anybody can tell me why the next code shows 4 messages with values
    10,1 11,1 12,1 and 13,1 but not only three first ones :shock:

    FOR decim := 10.1 TO 12.2 DO
    MESSAGE('%1',decim);

    As Navision Increments in 1's I would say at a guess
    10.1 + 1 output 10.1
    11.1 + 1 Output 11.1
    12.1 + 1 Output 12.1
    // Still not reached 12.2 so Increment again
    12.1 + 1 Output 13.1

    Now it's passed stop!
    Aghh no :shock: it done what you asked it to do!

    Date, Time, Integer and other numeric values all increment by 1, but Boolean ??

    How could you use a boolean in a FOR TO ??
    FOR Boolean := 0 TO 1 DO
    Message('%1',Boolean);

    Interesting! Anyone !!
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    TalinaTalina Member Posts: 8
    edited 2006-11-02
    David Cox wrote:
    As Navision Increments in 1's I would say at a guess
    10.1 + 1 output 10.1
    11.1 + 1 Output 11.1
    12.1 + 1 Output 12.1
    // Still not reached 12.2 so Increment again
    12.1 + 1 Output 13.1

    Now it's passed stop!
    Aghh no :shock: it done what you asked it to do!
    =; After decim=13.1 none of statements inside of loop must be executed
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Talina wrote:
    David Cox wrote:
    As Navision Increments in 1's I would say at a guess
    10.1 + 1 output 10.1
    11.1 + 1 Output 11.1
    12.1 + 1 Output 12.1
    // Still not reached 12.2 so Increment again
    12.1 + 1 Output 13.1

    Now it's passed stop!
    Aghh no :shock: it done what you asked it to do!
    =; After decim=13.1 none of statements inside of loop must be execated

    =; After the third loop it is only 12.1, it has not reached 12.2 has it?, So it outputs your message then increments to 13.1, that is the logic!

    Do you understand now it actions the code then increments after, so the first loop it has not incremented until after the output!

    You asked the question and that is the correct answer and why you get 4 messages!
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    David_CoxDavid_Cox Member Posts: 509
    BlackTiger wrote:
    FOR b := FALSE TO TRUE DO BEGIN
      MESSAGE('%1',b);
    END;
    

    It stupid but it works! :mrgreen:
    :lol:
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    krikikriki Member, Moderator Posts: 9,090
    BlackTiger wrote:
    FOR b := FALSE TO TRUE DO BEGIN
      MESSAGE('%1',b);
    END;
    

    It stupid but it works! :mrgreen:
    Actually, it is quite logical.
    And sometimes this is exactly what we need.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    TalinaTalina Member Posts: 8
    David Cox wrote:
    Talina wrote:
    David Cox wrote:
    As Navision Increments in 1's I would say at a guess
    10.1 + 1 output 10.1
    11.1 + 1 Output 11.1
    12.1 + 1 Output 12.1
    // Still not reached 12.2 so Increment again
    12.1 + 1 Output 13.1

    Now it's passed stop!
    Aghh no :shock: it done what you asked it to do!
    =; After decim=13.1 none of statements inside of loop must be execated

    =; After the third loop it is only 12.1, it has not reached 12.2 has it?, So it outputs your message then increments to 13.1, that is the logic!

    Do you understand now it actions the code then increments after, so the first loop it has not incremented until after the output!

    You asked the question and that is the correct answer and why you get 4 messages!

    Normally the sequence of actions is following:
    10.1 compare whith 12.2, output 10.1, 10.1 + 1
    11.1 compare whith 12.2, output 11.1, 11.1 + 1
    12.1 compare whith 12.2, output 12.1, 12.1 + 1
    13.1 compare whith 12.2, stop

    That's all
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Please read the answer's we give, and understand them, they are from years of Navision and Navision coding!

    In Navision the sequence of actions is following:
    10.1 output 10.1 THEN 10.1 + 1 Compare 10.1 DO
    11.1 output 11.1, 11.1 + 1 Compare 11.1 DO
    12.1 output 12.1, 12.1 + 1 Compare 12.1 DO
    13.1 output 13.1, 12.1 + 1 Compare 13.1 STOP

    This is the way Navision work, it might be different in other languages you know, but our answers are Navision based.

    ](*,)
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    TalinaTalina Member Posts: 8
    David Cox wrote:
    Please read the answer's we give, and understand them, they are from years of Navision and Navision coding!

    In Navision the sequence of actions is following:
    10.1 output 10.1 THEN 10.1 + 1 Compare 10.1 DO
    11.1 output 11.1, 11.1 + 1 Compare 11.1 DO
    12.1 output 12.1, 12.1 + 1 Compare 12.1 DO
    13.1 output 13.1, 12.1 + 1 Compare 13.1 STOP

    This is the way Navision work, it might be different in other languages you know, but our answers are Navision based.

    ](*,)

    Accordingly to your understanding of Navision the next code
    FOR decim := 10 TO 9 DO
    MESSAGE('%1',decim);

    will do following operations
    10 output 10, 10 + 1 Compare 9 STOP
    But Navision is more clever!
    It does not show message in this case =D>
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    BlackTiger wrote:
    FOR b := FALSE TO TRUE DO BEGIN
      MESSAGE('%1',b);
    END;
    

    It stupid but it works! :mrgreen:

    I have used this before in Reservations, where it is quite useful. ... think about it.
    David Singleton
  • Options
    David_CoxDavid_Cox Member Posts: 509
    edited 2006-11-02
    Talina wrote:
    David Cox wrote:
    Please read the answer's we give, and understand them, they are from years of Navision and Navision coding!

    In Navision the sequence of actions is following:
    10.1 output 10.1 THEN 10.1 + 1 Compare 10.1 DO
    11.1 output 11.1, 11.1 + 1 Compare 11.1 DO
    12.1 output 12.1, 12.1 + 1 Compare 12.1 DO
    13.1 output 13.1, 12.1 + 1 Compare 13.1 STOP

    This is the way Navision work, it might be different in other languages you know, but our answers are Navision based.

    ](*,)

    Accordingly to your understanding of Navision the next code
    FOR decim := 10 TO 9 DO
    MESSAGE('%1',decim);

    will do following operations
    10 output 10, 10 + 1 Compare 9 STOP
    But Navision is more clever!
    It does not show message in this case =D>

    I am sure Navision works out how many STEPS (Loops) first, just like REPEAT UNTIL And if there are none then skips the Code or the DO.

    FOR decim := 10 TO 9 DO
    MESSAGE('%1',decim);

    STEPS = 0

    This is silly code it never starts because there is no 10 TO 9 in Navision is there?
    but did you know there is a 10 DOWNTO 9?

    My answer is simple stepping up +1 or down -1 it does the code before the increment and checking the condition!

    NOW TRY THESE EXAMPLES, This one will output and then Increment
    FOR decim := 10 TO 10 DO // Steps +1
    MESSAGE('%1',decim);

    STEPS * 1

    FOR decim := 10 DOWNTO 9 DO // This will also output Steps -1
    MESSAGE('%1',decim);

    STEPS * 2

    Navision is very clever and my understanding of Navision code is very good, thanks!

    So when you ask for advise study the answers and test properly, before challanging, we answer these questions as a help, and the advice we give can be used or not, but if you know better, why ask??

    =; :lol: =D> \:D/
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    SavatageSavatage Member Posts: 7,142
    This post is becoming a runaway train.

    I love it! :lol:
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Savatage wrote:
    This post is becoming a runaway train.

    I love it! :lol:

    Hard work is the phrase I would use :lol:
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    David_CoxDavid_Cox Member Posts: 509
    BlackTiger wrote:
    I've tested in C#:
    float i = 10.1f;
    for (i = 10.1f; i <= 12.2f; i++)
    {
       MessageBox.Show(String.Format("{0}", i));
    }
    

    Result was "10.1", "11.1", "12.1"... :-k

    I dont know c# but how would you code it to increment after the Message?
    float i = 10.1f;
    for (i = 10.1f; i <= 12.2f)
    {
    MessageBox.Show(String.Format("{0}", i));
    i++;
    }

    I think this is how Navision is working!
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    garakgarak Member Posts: 3,263
    @Blacktiger

    Thats not right! In C# you can say how the compiler should increment the variable in foor loop :!: Also in C an VB or other (right) Languages
    float i = 10.1f;
    float incrementer = incrementer + 0.1f;
    for (i; i <= 11.3f; incrementer)
    {
      MessageBox.Show(String.Format("{0}", i));
    }
    

    But Navision doesn't allow an manuell increment (step). The only way is to use an While loop.

    Regards
    Do you make it right, it works too!
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    C/SIDE was based on Pascal, not C# or C++

    There is a huge base of code based on the rules of the C/SIDE language that has not really changed in 18 years when 3.00 DOS was released.

    Imagine the impact if they sddenly changed how the compiler worked. Next Technical upgrade would requre a complete analysis of everywhere that a structure is used.

    Navision is a Business Application, it is NOT a programming Language.
    David Singleton
  • Options
    TalinaTalina Member Posts: 8
    David Cox wrote:
    So when you ask for advise study the answers and test properly, before challanging, we answer these questions as a help, and the advice we give can be used or not, but if you know better, why ask??
    /

    I see you enjoy to dispute not to listen your opponent. This is your right.
    Besides I undestand the subject enough good.
    So the aim of this forum topic is to prevent other developpers from possible errors.
    This is my last answer, bye :-#
Sign In or Register to comment.