Compare length of two strings: Difference between revisions
→{{header|GWBASIC}}
Line 327:
10 'SAVE "SSTRING",A
20 ' Length of a group of strings
30 CLS▼
▲40 OPTION BASE 1
▲50 DIM SSTRING$(10)
60 ' Begin of program cycle
▲60 I=0: J=1
70
80
90 PRINT "Enter an empty string to finish anytime."
100 PRINT
100 IF SSTRING$(J)="" THEN 150 ' Exit Do▼
110 ' Do
110 IF J>1 THEN GOSUB 250 ' Autosort▼
120
130
150 ' Show results▼
190 PRINT "You entered";J;"strings. Lengths are as follows:"▼
200 FOR I=1 TO J▼
200 J = J - 1
210 PRINT USING "##. &: ## chars."; I;SSTRING$(I);LEN(SSTRING$(I))▼
210 IF J<1 THEN PRINT "You entered no strings.": GOTO 260
230 PRINT: PRINT "End of program execution."▼
240 END▼
250 ' Autosort subroutine▼
270 WHILE I>1▼
280 IF LEN(SSTRING$(I)) > LEN(SSTRING$(I-1)) THEN SWAP SSTRING$(I), SSTRING$(I-1)▼
290 I=I-1▼
310 RETURN▼
330 WEND
</syntaxhighlight>
{{out}}
The user enters a list of up to 10 strings
<pre>
Capture the string 3 (up to 10, Enter to finish)? abcdef▼
Capture the string
Capture the string
Capture the string 4: 1234567
Capture the string 5:
You entered 4 strings. Lengths are as follows:
|