Jump to content
IGNORED

Brain lapse


Opry99er

Recommended Posts

I'm having a brain lapse right now... please assist!

 

This first piece of code fails with a syntax error. The second functions as expected.

 

 

Thanks!

 

 

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10
 
 
 
10 CALL CLEAR
20 FOR T=110 TO 880 STEP 110
30 IF T=770 THEN S=834 ELSE S=T
40 CALL SOUND(200,220,1,440,1,S,1)
50 NEXT T
60 GOTO 10
 

 

Link to comment
Share on other sites

I'm having a brain lapse right now... please assist!

 

This first piece of code fails with a syntax error. The second functions as expected.

 

 

Thanks!

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10
 
 
 
10 CALL CLEAR
20 FOR T=110 TO 880 STEP 110
30 IF T=770 THEN S=834 ELSE S=T
40 CALL SOUND(200,220,1,440,1,S,1)
50 NEXT T
60 GOTO 10
 

Everything after the ELSE is part of the ELSE statement2.

 

You would need to start a new line after S=T.

 

Or embed the comparison in a formula like this:

10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: S=T-(T=770)*64 :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10
  • Like 2
Link to comment
Share on other sites

Balls, that's clever.

 

I don't fully get the T=770 within the parenthesis multiplied by 64, but it works.

 

Care to break it down a bit for me?

 

I should give Erik a chance to answer, but (T=770) is a logical relational expression that evaluates to TRUE (-1) or FALSE (0). You can do the rest of the math, I think. [see Erik’s (@FarmerPotato’s) post below.]

 

...lee

Link to comment
Share on other sites

Balls, that's clever.

 

I don't fully get the T=770 within the parenthesis multiplied by 64, but it works.

 

Care to break it down a bit for me?

 

From page 41 of the XB manual

RELATIONAL EXPRESSIONS

 Relational expressions are most often used in the IF-THEN-ELSE statement, but may be used anywhere that numeric expressions are allowed. 
A relational expression has a value of -1 if it is true and a value of 0 if it is false

Evaluate S=T-(T=770)*64

 

T    T=770  *64   T-that
===  =====  ===   =====
660    0      0     660
770   -1    -64     834
880    0      0     880


  • Like 2
Link to comment
Share on other sites

I should add that any non-zero value is considered TRUE. A relational expression that is true always evaluates to -1 (all bits on), so if you expanded your example to (1+1=1)+(1+1=2)+(1+2=3) = 0+(-1)+(-1), it would evaluate to -2, which is still considered true even though it does not evaluate to -1—simply because it is not 0. If you want results that evaluate only to -1 when true, you would need to use the logical operators (OR,AND) on the relational expressions instead of the arithmetic operators (+,*).

 

...lee

  • Like 1
Link to comment
Share on other sites

I thought you meant backwards so the answer is still right... than I reevaluated!

Hence...

 

(1+1=1)+(1+1=2)=1 or OR logic TRUE

(1+1=1)*(1+1=2)=0 or AND logic FALSE

 

I took a pill... am I doing any better now. :lol:

 

I'm not very smart so I always like to get the machine's opinion on the matter. :-)

post-50750-0-85979700-1542332467.jpg

Link to comment
Share on other sites

I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing :) I'm more procedural...

 

expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW

 

Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. :)

Link to comment
Share on other sites

I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing :) I'm more procedural...

 

expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW

 

Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. :)

 

I took my math from your post, so the credit is all yours.

 

Like I said, I'm not that smart. :-D

  • Like 1
Link to comment
Share on other sites

This first piece of code fails with a syntax error.

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10

The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line. This is not allowed* under normal operation.

 

(If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable)

  • Like 2
Link to comment
Share on other sites

The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line. This is not allowed* under normal operation.

 

(If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable)

The result will be a non initialized variable and a crash of XB.

Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work.

 

PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers.

Link to comment
Share on other sites

The result will be a non initialized variable and a crash of XB.

Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work.

 

PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers.

That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result.

 

Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions.

 

10 I,X=0

11 !@P-

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I

 

I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing. I haven't encountered any ill effects with XB version 110.

  • Like 3
Link to comment
Share on other sites

That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result.

 

Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions.

 

10 I,X=0

11 !@P-

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I

 

I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing. I haven't encountered any ill effects with XB version 110.

As I said PRESCAN looks for and sets up Variables so your example followed exactly what I said thanks.

Link to comment
Share on other sites

I disagree. The FOR/NEXT error has nothing to do with variable scanning and setup. Two separate issues altogether.

 

Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR.

 

11 !@P-

12 I,X=0

100 FOR I=1 TO 10 :: IF I=5 then X=X+100 :: PRINT X;"I was 5" :: NEXT I

110 X=X+1 :: PRINT X :: NEXT I

So why do you think it says SYNTAX ERROR in LINE 12???

Yet if you delete LINE 11 it finds the real SYNTAX ERROR IN 100? (NEXT AT THE END OF A IF THEN)

Now take out the :: NEXT I at end of the IF THEN

And magically it now works? HUH? What do you think is going on?

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I

Link to comment
Share on other sites

 

Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR.

The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12.

Link to comment
Share on other sites

The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12.

Very True, and what I said about PRESCAN is also true...which is why you had to bypass it. with !@P-

 

I know the inside of XB code pretty well and it does not do a great job of analyzing exaclty what the problem is so defaults to SYNTAX ERROR

 

Even when that is not the problem.

Edited by RXB
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...