dbTalk Databases Forums  

What is the answer?

comp.databases.pick comp.databases.pick


Discuss What is the answer? in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Albert D. Kallal
 
Posts: n/a

Default Re: What is the answer? - 02-12-2007 , 10:00 AM






Quote:
Looks like jBase is anticipating loop termination and so skips directly.
Yes..that makes sense.

Not at all surprising, since the code is converted to c++, and then
compiled.

if you every tried to run null loops in c to create a delay..you in for a
surprise..as the compiler will completely skip the code...

for x = 1; x <= 100000; x++)
{};


In VB6, VBA, or mvBasic, those loops are executed...even when they do
nothing.

However, in c, the above loop is looked at by the compiler...and simply
skipped.....

The same thing is done for redundant variable assigns etc. so, even if you
go:

for x = 1; x <= 100000; x++)
{y = 123};

Even in the above, the compiler figures out no other variables and refs
occur to "y", so it moves it out of the loop......once again, the compiler
will simply skip the above loop....

So, not one bit surprised that jBase skips the loop, since jBase code is
converted to c..and then compiled....

--
Albert D. Kallal
Edmonton, Alberta Canada
pleaseNOOSpamKallal (AT) msn (DOT) com




Reply With Quote
  #12  
Old   
GVP
 
Posts: n/a

Default Re: What is the answer? - 02-12-2007 , 11:35 AM






What C compiler do:

int i=10, j=11;
for( i = 1, j= 0; i<10 ; i++)
{
....
}

xxxxx

1 in any case sets i to 1
2 in any case sets j to 0
3 checks condition i < 10 if TRUE then goto4 else goto7
4 executes {...}
5 executes i++
6 goto3
7 xxxxx


In case: FOR I=10 TO 1
I think that DataBasic compiler checks that condition is constant and
always FALSE. In this case compiler ignores entire FOR.
Quote:
incorrect program causes incorrect result.
Regards,
Grigory



Reply With Quote
  #13  
Old   
Tony Gravagno
 
Posts: n/a

Default Re: What is the answer? - 02-12-2007 , 04:27 PM



I can picture the code that's being executed in the 10 TO 1 issue.
It's always been my understanding that the FOR statement checks to see
if the incremented value exceeds the limit, then does the increment
and enters the loop if it does not. It seems most platforms assign
the initial value, then check, where Universe checks then increments.
We're talking about the placement of one high level statement (2-3
assembler lines?). In another life that wouldn't be wrong but at this
point if they want to follow established precedent then it is wrong.

T

John Henderson wrote:
Quote:
The point is that unlike
FOR A = 10 TO 10
the statement
FOR A = 10 TO 1
under uniVerse does _not_ set the variable A at all. It's left
at its previous value if it had one, or left unassigned if not.
It's as if the FOR loop never even existed.

The D3 result is correct

I accept that it's not incorrect.

John


Reply With Quote
  #14  
Old   
John Henderson
 
Posts: n/a

Default Re: What is the answer? - 02-12-2007 , 05:49 PM



Tony Gravagno wrote:

Quote:
I can picture the code that's being executed in the 10 TO 1
issue. It's always been my understanding that the FOR
statement checks to see if the incremented value exceeds the
limit, then does the increment and enters the loop if it does
not. It seems most platforms assign the initial value, then
check, where Universe checks then increments. We're talking
about the placement of one high level statement (2-3 assembler
lines?). In another life that wouldn't be wrong but at this
point if they want to follow established precedent then it is
wrong.
Precedent aside, and having had a look at the Basic Commands
Reference, I agree. The behaviour I see is wrong. For the
statement

FOR variable = start TO end [STEP increment]

the manual says (without reservation) "variable is assigned the
value of start, which is the initial value of the counter."

QED.

John


Reply With Quote
  #15  
Old   
Chandru Murthi
 
Posts: n/a

Default Re: What is the answer? - 02-13-2007 , 08:12 AM



In an ideal world, depending on the index variable outside the scope of the
For-Next is not allowed--fortran et al leave it undefined. But I've written
many times (before we had EXIT):

FOR i= 1 to imax
IF (terminating condition) THEN i=999999
END ELSE
END
NEXT i
IF i >= 999999 THEN
error
END

I could've, of course set imax to -1 which is a better test anyway.

Chandru Murthi

"John Henderson" <jhenRemoveThis (AT) talk21 (DOT) com> wrote

Quote:
Tony Gravagno wrote:

I can picture the code that's being executed in the 10 TO 1
issue. It's always been my understanding that the FOR
statement checks to see if the incremented value exceeds the
limit, then does the increment and enters the loop if it does
not. It seems most platforms assign the initial value, then
check, where Universe checks then increments. We're talking
about the placement of one high level statement (2-3 assembler
lines?). In another life that wouldn't be wrong but at this
point if they want to follow established precedent then it is
wrong.

Precedent aside, and having had a look at the Basic Commands
Reference, I agree. The behaviour I see is wrong. For the
statement

FOR variable = start TO end [STEP increment]

the manual says (without reservation) "variable is assigned the
value of start, which is the initial value of the counter."

QED.

John



Reply With Quote
  #16  
Old   
Jim Idle
 
Posts: n/a

Default Re: What is the answer? - 02-13-2007 , 11:13 AM



On Feb 11, 2:06 pm, Tony Gravagno
<g6q3x9lu53... (AT) sneakemail (DOT) com.invalid> wrote:
Quote:
John Henderson wrote:
uniVerse 10 = 5, consistent with the very telling result from
running the 4-line program:

FOR A = 10 TO 1
PRINT "HELLO WORLD"
NEXT A
PRINT A

namely:

Program "T3": Line 4, Variable "A" previously undefined. Empty
string used.

This seems to be the result of engineer attemptS to maintain some form
of local scope versus global. While in the loop the variable space
referenced is the local instance while outside the loop that local
instance no longer exists so the global instance is used.
NO, this has nothing to do with that. BASIC does not have any scoping.
It is to do with whether the compiler decides it can do any
opimizations of loop initialization vs iteration vs having the loop at
all. I suspect that the UniVerse compiler here is incorrect and that
the variable A should be intialized to 1 even if the loop code is
eliminated.

I don't remember making the jBASE compiler do anything that would
cause the result to be 9, so if this is truly the resutl on jBASE 4,
then I suspect that someone played with the compiler or runtime for
loops at the jBASE 4.0 level and it has been corrected at 4.1. Someone
should check jBASE 3.x although it is farily irrelevant as the code is
in error of course and one should not program for side effects (thoguh
perhaps people do not see that they are doing so if this was FOR X=A
TO B STEP V for instance.

However I DO vaguely remember making the compiler check that the start
and end points made sense when the arguments were literal constants.
It might be that this warning would only be issued if you used (W4
warning levels on the jBASE compiler.

The reason for the warning is because the behavior of syntactically
sound but semantically incorrect code is undefined. This is the case
in many languages and compilers. In the case of jBASE I was not
exactly hampered by but had to pay attention to the behavior of
existing systems. Sounds like this particular case was overlooked at
some point in development.

Other 'interesting' cases you might like to try if you are bored, are:

IF 3=4 THEN PRINT 5
IF 4=4 THEN PRINT 6

Jim




Reply With Quote
  #17  
Old   
Mark Brown
 
Posts: n/a

Default Re: What is the answer? - 02-13-2007 , 12:44 PM




"Jim Idle" <jimi (AT) temporal-wave (DOT) com> wrote

Quote:
IF 3=4 THEN PRINT 5
IF 4=4 THEN PRINT 6

Jim


Jim, I once worked with a wonderful older gentleman who insistend in writing
code such as:

if FLAG=FALSE then FLAG=FALSE

I'd say Why? And he's say he just was making sure. He didn't trust the
computer.


Mark Brown




Reply With Quote
  #18  
Old   
Chandru Murthi
 
Posts: n/a

Default Re: What is the answer? - 02-13-2007 , 01:28 PM



On a related note:
Since line 1 in this code is mandatory:
0001 STRING = ''
0002 STRING<I> = some.value

I see code all the time where
0001 STRING = ''
0002 STRING = some.value

Jes' makin' sure, eh?

Chandru

"Mark Brown" <mbrown (AT) drexelmgt (DOT) com> wrote

Quote:
"Jim Idle" <jimi (AT) temporal-wave (DOT) com> wrote in message
news:1171386813.675035.296520 (AT) h3g2000cwc (DOT) googlegroups.com...

IF 3=4 THEN PRINT 5
IF 4=4 THEN PRINT 6

Jim


Jim, I once worked with a wonderful older gentleman who insistend in
writing code such as:

if FLAG=FALSE then FLAG=FALSE

I'd say Why? And he's say he just was making sure. He didn't trust the
computer.


Mark Brown




Reply With Quote
  #19  
Old   
Beliavsky
 
Posts: n/a

Default Re: What is the answer? - 02-13-2007 , 04:44 PM



On Feb 13, 9:12 am, "Chandru Murthi"
<cmur_xyz_thi (AT) xyz_seeinggree_xyz_n (DOT) net> wrote:
Quote:
In an ideal world, depending on the index variable outside the scope of the
For-Next is not allowed--fortran et al leave it undefined.
That is incorrect regarding Fortran. For the code

do i=1,2
print*,i
end do
print*,i

the variable "i" has value 3 after exiting the loop, and the code must
give the result

1
2
3



Reply With Quote
  #20  
Old   
Chandru Murthi
 
Posts: n/a

Default Re: What is the answer? - 02-14-2007 , 09:19 AM



Last I used Fortran was in 1971 on an IBM 370, so quite possibly things have
changed since then. My point was only that it may not be good programming
practice to depend on an index var's value, it's better to use your own
flags.

Chandru

"Beliavsky" <beliavsky (AT) aol (DOT) com> wrote

Quote:
On Feb 13, 9:12 am, "Chandru Murthi"
cmur_xyz_thi (AT) xyz_seeinggree_xyz_n (DOT) net> wrote:
In an ideal world, depending on the index variable outside the scope of
the
For-Next is not allowed--fortran et al leave it undefined.

That is incorrect regarding Fortran. For the code

do i=1,2
print*,i
end do
print*,i

the variable "i" has value 3 after exiting the loop, and the code must
give the result

1
2
3




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.