So I load this into the BASIC programme and hit Run but just get an error message, "No such variable". Is that supposed to happen? I am trying to test a very basic linear search program for the decision maths course. This one seemed to fit the bill.... kr
DATA FRED,17,BILL,21,ALLISON,21,NOEL,32
DATA JOAN,26,JOHN,19,WENDY,35,ZZZZ,0
REPEAT
READ list$,age
IF list$=name$ THEN PRINT name$,age
UNTIL list$=name$ OR list$="ZZZZ"
IF list$="ZZZZ" PRINT "Name not in list"
linear data search error query
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: linear data search error query
As far as I can see it's complaining that the variable name$ in this line doesn't exist:gerard@dugdill.com wrote: ↑Tue 06 May 2025, 10:15 So I load this into the BASIC programme and hit Run but just get an error message, "No such variable". Is that supposed to happen?
Code: Select all
IF list$=name$ THEN PRINT name$,age
-
- Posts: 11
- Joined: Wed 25 Sep 2024, 13:35
Re: linear data search error query
I am not sure. I seemed to find the exact program I was looking for when looking through the DATA entry in the keyword section of the help guide manual, excerpt below.
DATA...
The following example program segment reads through a list of names looking for the name in 'name$'. If the name is found, the name and age are printed. If not, an error message is printed.
DATA FRED,17,BILL,21,ALLISON,21,NOEL,32
DATA JOAN,26,JOHN,19,WENDY,35,ZZZZ,0
REPEAT
READ list$,age
IF list$=name$ THEN PRINT name$,age
UNTIL list$=name$ OR list$="ZZZZ"
IF list$="ZZZZ" PRINT "Name not in list"
DATA...
The following example program segment reads through a list of names looking for the name in 'name$'. If the name is found, the name and age are printed. If not, an error message is printed.
DATA FRED,17,BILL,21,ALLISON,21,NOEL,32
DATA JOAN,26,JOHN,19,WENDY,35,ZZZZ,0
REPEAT
READ list$,age
IF list$=name$ THEN PRINT name$,age
UNTIL list$=name$ OR list$="ZZZZ"
IF list$="ZZZZ" PRINT "Name not in list"
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: linear data search error query
Yes, but as it says that's only a program segment to illustrate one use of DATA, not a self-contained program. Like most code examples in the manual, it's not useful on its own but only as part of a larger program. What are you trying to do?gerard@dugdill.com wrote: ↑Wed 07 May 2025, 17:47 I seemed to find the exact program I was looking for when looking through the DATA entry in the keyword section of the help guide manual, excerpt below.
-
- Posts: 11
- Joined: Wed 25 Sep 2024, 13:35
Re: linear data search error query
Run the whole program to search for a particular data item using linear search (and then binary search).
Often hit the no such variable barrier.
)
Often hit the no such variable barrier.
)
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: linear data search error query
The binary-chop method is described, in flow-chart form, here. I use it quite commonly myself.gerard@dugdill.com wrote: ↑Thu 08 May 2025, 12:13 Run the whole program to search for a particular data item using linear search (and then binary search).
-
- Posts: 11
- Joined: Wed 25 Sep 2024, 13:35