? on For Next Loops
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-07 09:01 PM
‎2006-09-07
09:01 PM
FOR dist=0 TO 30' STEP brick_tie
ADDx dist
GOSUB 111
NEXT dist
RETURN
Will this work in an object? It's just putting 1 in and that's it. The brick_tie is a parameter for a length. GOSUB 111 is the actual lines for the brick tie.
Thanks for any help,
Michele
17 REPLIES 17
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-08 09:33 PM
‎2006-09-08
09:33 PM
Thanks Tom.
I know someone who has a strong computer science background
and I will ask him some of these questions and maybe he will
have some answers.
Thanks,
Peter Devlin
I know someone who has a strong computer science background
and I will ask him some of these questions and maybe he will
have some answers.
Thanks,
Peter Devlin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-08 10:02 PM
‎2006-09-08
10:02 PM
Peter wrote:C++ can use steps of course and more.
Hello Tom,
Does the C++ for loop have the "step" part like GDL ?
Peter Devlin
A problem may arise for both FOR and WHILE, as result of roundings and comparing floating numbers. ( GDL, C++,...).
Both variants above are IMHO almost equivalent and not quite correct.
IMHO better
FOR dist=0 TO 30 ' + brick_tie / 2 STEP brick_tie
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-08 10:29 PM
‎2006-09-08
10:29 PM
Hello Oleg,
Great to hear from you.
You say," Both variants above are IMHO almost equivalent
and not quite correct."
Could you elaborate a little please.
How are they both not quite correct ?
Thank you,
Peter Devlin
Great to hear from you.
You say," Both variants above are IMHO almost equivalent
and not quite correct."
Could you elaborate a little please.
How are they both not quite correct ?
Thank you,
Peter Devlin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-08 10:50 PM
‎2006-09-08
10:50 PM
Peter wrote:Well. Some tests ( AC9 )
Hello Oleg,
Could you elaborate a little please.
How are they both not quite correct ?
Thank you,
Peter Devlin
What do you think will printed
counter = 0 bstep = 3 FOR dist=0 TO 3 STEP bstep counter = counter + 1 NEXT dist PRINT counterImagine there was some calculations.
bstep is same, but what will be printed now
counter = 0 bstep = 0.3/0.1 FOR dist=0 TO 3 STEP bstep counter = counter + 1 NEXT dist PRINT counterSame for WHILE
counter = 0 bstep = 0.3 dist = 0 WHILE dist < 0.3 DO dist = dist + bstep counter = counter + 1 ENDWHILE PRINT counter counter = 0 bstep = 1 - 0.7 dist = 0 WHILE dist < 0.3 DO dist = dist + bstep counter = counter + 1 ENDWHILE PRINT counterThe result will depend on actual values and calculations that's mean unstable.
Oleg
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-08 11:10 PM
‎2006-09-08
11:10 PM
Hello Oleg,
Thank you for your considerable elaboration.
I will have to copy your code into a lib part and
get my head around what is happening.
Thank you,
Peter Devlin
Thank you for your considerable elaboration.
I will have to copy your code into a lib part and
get my head around what is happening.
Thank you,
Peter Devlin
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-09 01:42 AM
‎2006-09-09
01:42 AM
Hello Oleg,
I did an experiment with your second piece of code.
counter = 0
bstep = 0.3/0.1 !!!=3
FOR dist=0 TO 3 STEP bstep
counter = counter + 1
NEXT dist
PRINT counter !!!! prints 1
PRINT 0.3/0.1 !!!! prints 3
When I change the code to this.
counter = 0
bstep = int(0.3/0.1) !!!=3
FOR dist=0 TO 3 STEP bstep
counter = counter + 1
NEXT dist
PRINT counter !!!! prints 2
It is as though there is a secret fractional part
of the calculation of 0.3/0.1 that is not displayed
in what is printed in PRINT 0.3/0.1 and that there
is a rounding-up in the internal calculations.
How can this be ???
Is PRINT able to lie ?
I wonder how many places PRINT can display.
Peter Devlin
I did an experiment with your second piece of code.
counter = 0
bstep = 0.3/0.1 !!!=3
FOR dist=0 TO 3 STEP bstep
counter = counter + 1
NEXT dist
PRINT counter !!!! prints 1
PRINT 0.3/0.1 !!!! prints 3
When I change the code to this.
counter = 0
bstep = int(0.3/0.1) !!!=3
FOR dist=0 TO 3 STEP bstep
counter = counter + 1
NEXT dist
PRINT counter !!!! prints 2
It is as though there is a secret fractional part
of the calculation of 0.3/0.1 that is not displayed
in what is printed in PRINT 0.3/0.1 and that there
is a rounding-up in the internal calculations.
How can this be ???
Is PRINT able to lie ?
I wonder how many places PRINT can display.
Peter Devlin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-09 09:42 AM
‎2006-09-09
09:42 AM
PRINT does not lie. It rounds number to some signs before display ( it seems to 6 signs ).
In any case it needs to be ready, that issues may arise at any comparisons of floating numbers. ( like 0.3 is not equal 1-0.7 )
And if it important in script, use some tricks, like ABS, EPS etc
( It seems there is some guide from GS about that )
FOR loop uses internally comparison too and it may results to unexpected results. Therefore, when a loop uses floating numbers, and not integer, better to use it like
FOR dist=0 TO 3 + bstep / 2 STEP bstep
Oleg
In any case it needs to be ready, that issues may arise at any comparisons of floating numbers. ( like 0.3 is not equal 1-0.7 )
And if it important in script, use some tricks, like ABS, EPS etc
( It seems there is some guide from GS about that )
FOR loop uses internally comparison too and it may results to unexpected results. Therefore, when a loop uses floating numbers, and not integer, better to use it like
FOR dist=0 TO 3 + bstep / 2 STEP bstep
Oleg
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2006-09-09 09:13 PM
‎2006-09-09
09:13 PM
Hello Oleg,
Yes, this is something that I have only recently come to understand.
Now, all I need to do is remember to put in that little extra to
help AC make it to the finish line.
Thanks Oleg,
Peter Devlin
Yes, this is something that I have only recently come to understand.
Now, all I need to do is remember to put in that little extra to
help AC make it to the finish line.
Thanks Oleg,
Peter Devlin
- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »