FOR..TO loop with decimal start/end value
Talina
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);
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);
0
Comments
-
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!0 -
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"
, but also only with step 1 
RegardsDo you make it right, it works too!0 -
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 numeric0 -
This means it CAN be used, but it is not always adviced.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 numericRegards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Many manuals for beginners have such inaccuracies.
How we can pass exams well :?
Never believe!
Allways check!0 -
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.com0 -
=; After decim=13.1 none of statements inside of loop must be executedDavid 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!0 -
Talina wrote:
=; After decim=13.1 none of statements inside of loop must be execatedDavid 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 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.com0 -
BlackTiger wrote:
FOR b := FALSE TO TRUE DO BEGIN MESSAGE('%1',b); END;
It stupid but it works!
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.com0 -
Actually, it is quite logical.BlackTiger wrote:FOR b := FALSE TO TRUE DO BEGIN MESSAGE('%1',b); END;
It stupid but it works!
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!0 -
David Cox wrote:Talina wrote:
=; After decim=13.1 none of statements inside of loop must be execatedDavid 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 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 all0 -
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.com0 -
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>0 -
BlackTiger wrote:
FOR b := FALSE TO TRUE DO BEGIN MESSAGE('%1',b); END;
It stupid but it works!
I have used this before in Reservations, where it is quite useful. ... think about it.David Singleton0 -
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??
=;
=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.com0 -
This post is becoming a runaway train.
I love it!
0 -
Savatage wrote:This post is becoming a runaway train.
I love it!
Hard work is the phrase I would use
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.com0 -
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.com0 -
@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) Languagesfloat 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.
RegardsDo you make it right, it works too!0 -
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 Singleton0 -
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 :-#0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
