|
Post by plus on Jul 30, 2022 14:35:37 GMT
I would indent the while wend also. I would simplify the opt 4 code and put it as the while wend test. So you can only use 1-3 or exit with 4, all other input is ignored. WHILE opt<>4
CLS PRINT "CHOOSE OPTION 1-4." PRINT "Last Choice ";opt PRINT "1. Possible preparatory task" PRINT "2. One of the routine tasks" PRINT "3. Different routine task" PRINT "4. EXIT the program" PRINT INPUT "What is your choice? ";opt
SELECT CASE opt CASE 1 'code for performing preparatory task CASE 2 'code for performing a routine task 'code may include submenu CASE 3 'code for different routine task 'code could include submenu CASE ELSE 'do nothing END SELECT WEND
PRINT "Goodbye" END
A little nip and tuck: WHILE 1 ' opt<>4 NOW you do a task come back to menu select another... again... until case 4 scan ' offer a way out of loop if user cant figure out case 4 CLS PRINT "CHOOSE OPTION 1-4." PRINT PRINT "1. Possible preparatory task" PRINT "2. One of the routine tasks" PRINT "3. Different routine task" PRINT "4. EXIT the program" PRINT INPUT "What is your choice? ";opt
SELECT CASE opt CASE 1 'code for performing preparatory task CASE 2 'code for performing a routine task 'code may include submenu CASE 3 'code for different routine task 'code could include submenu CASE 4 PRINT "Goodbye" ' coded way out END END SELECT WEND
|
|
|
Post by Rod on Jul 30, 2022 14:48:52 GMT
I think we are doing the same thing, I use WHILE opt<>4 you use CASE 4 so same flow really. I inserted CASE ELSE but it isn't really needed. Its either act on 1,2 or 3 or exit on 4 in both cases. Both sets of code loop till opt = 4. The difference is that my code exits the WHILE WEND loop and allows the program to continue. The CASE 4 code only allows END or worse still in structured programming terms GOTO. We have yet to show this sort of loop nested in wider code. Bye the way, there is a tough drawing challenge for you over on the Liberty Forum. The shell like yellow image. libertybasiccom.proboards.com/thread/2062/more-old-basic-books
|
|
|
Post by plus on Jul 30, 2022 16:58:57 GMT
I think we are doing the same thing, I use WHILE opt<>4 you use CASE 4 so same flow really. I inserted CASE ELSE but it isn't really needed. Its either act on 1,2 or 3 or exit on 4 in both cases. Both sets of code loop till opt = 4. The difference is that my code exits the WHILE WEND loop and allows the program to continue. The CASE 4 code only allows END or worse still in structured programming terms GOTO. We have yet to show this sort of loop nested in wider code. Bye the way, there is a tough drawing challenge for you over on the Liberty Forum. The shell like yellow image. libertybasiccom.proboards.com/thread/2062/more-old-basic-booksYeah I was thinking it wouldn't loop after option 1 or 2 but I guess it would, plus I was concerned about hitting say 5 or just enter but OK that way too, yeah same difference alright! My excuse is I didn't have my coffee yet. Re Liberty link to magazine cover: Well dang! There goes my afternoon ;-)) It reminds me of those colored shells we were doing, remember those, "A shell of a different color"
|
|
|
Post by jarychk on Jul 30, 2022 21:59:19 GMT
Having two comments currently, just one of them seems best for right now.
When at the main menu, user makes a main menu pick choice. Inside there can be another menu. This is when the code becomes more difficult to write and keep neatly and visually nicely organized. I found that some of such code may be arranged as subroutines, and the subroutines codeblocks can be placed after the END statement. Yet a program may be still more difficult to read and to develop when the main menu's cases have sub-cases, more menues inside them. Another thing to consider for code giving more menues within the main block SELECT CASE is to use IF type decision structures ( yes and be sure to indent to help in reading the code ).
|
|