Search a list of records: Difference between revisions

(Search a list of records in FreeBASIC and others BASIC dialents)
(→‎{{header|Commodore BASIC}}: Add implementation.)
Line 802:
 
=={{header|BASIC}}==
==={{header|Commodore BASIC}}===
C= BASIC has no associative data structure, so this just uses a two-dimensional array. It is written to accept a dynamically-sized list of cities and populations, with an empty-string sentinel indicating the end of the list. Note that in text mode (upper/lowercase), BASIC keywords are only recognized in lowercase.
<lang gwbasic>100 nc=0
110 read n$
120 if n$="" then 160
130 read p$
140 nc=nc+1
150 goto 110
160 restore
170 dim ci$(nc-1,1)
180 for i=0 to nc-1
190 : for j=0 to 1
200 : read ci$(i,j)
210 : next j
220 next i
230 for i=0 to nc-1
240 : if ci$(i,0) = "Dar Es Salaam" then print i:goto 260
250 next i
260 for i=0 to nc-1
270 : p=val(ci$(i,1))
280 : if p<5 then print ci$(i,0): goto 300
290 next i
300 for i=0 to nc-1
310 : if left$(ci$(i,0),1)="A" then print ci$(i,1):goto 330
320 next i
330 end
340 data "Lagos", 21.0
350 data "Cairo", 15.2
360 data "Kinshasa-Brazzaville", 11.3
370 data "Greater Johannesburg", 7.55
380 data "Mogadishu", 5.85
390 data "Khartoum-Omdurman", 4.98
400 data "Dar Es Salaam", 4.7
410 data "Alexandria", 4.58
420 data "Abidjan", 4.4
430 data "Casablanca", 3.98
440 data ""</lang>
 
{{Out}}
<pre>ready.
run
6
Khartoum-Omdurman
4.58
 
ready.</pre>
 
==={{header|FreeBASIC}}===
<lang freebasic>Type Registro
1,480

edits