Qbasic looping programs. Wap to print all odd number from 1 to 100 cls a=1 b=1. B=b+1 loop end wap to print all even numbers from 1 to 100 cls a=2 b=1.
- Gw Basic Sample Programs
This question already has an answer here:
- How do I break out of nested loops in Java? 33 answers
If I have loop in a loop and once an
if statement is satisfied I want to break main loop, how am I supposed to do that?
This is my code:
marked as duplicate by Steve Chambers, Mark Rotteveel javaOct 26 '16 at 14:10
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Using a labeled break:
Jigar JoshiJigar Joshi
You can add labels to your loop, and use that
labelled break to break out of the appropriate loop: -
See these links for more information:
Rohit JainRohit Jain
You can just
return the control from that function. Or use the ugly
break labels approach :)
If there is another code parts after your
for statement, you can refactor the loops in a function.
IMO, the use of breaks and continue should be discouraged in OOP, since they affect the readability and the maintenance. Sure, there are cases where they are handy, but in general I think that we should avoid them, since they will encourage the use of goto style programing.
Apparently variations to this questions are posted a lot. Here Peter provided some good and odd uses using labels.
It looks like for Java a labeled break appears to be the way to go (based on the consensus of the other answers).
But for many (most?) other languages, or if you want to avoid any
goto like control flow, you need to set a flag:
Just for fun:
break label : it's a forward goto. It can break any statement and jump to the next:
Keshav bansalKeshav bansal
Not the answer you're looking for? Browse other questions tagged javaloopssyntaxfor-loopbreak or ask your own question.
GW-BASIC is a dialect of the programming language BASIC developed by Microsoft in the 1980s, and was included in most versions of MS-DOS. It is similar to Microsoft/IBM BASICA, but is a fully self-contained executable.
Commands in GWBASIC
I am using GWBASIC and cannot figure out a few things. Like, when I'm saving a program after running it with F4, it says: File not found.Secondly, when I'm using auto command it shows * with line ...
How to read a protected .bas file which has “line buffer overflow”?
I have an old file which I'd like to read its code.The file has no extension. Right click + open with notepad gives me something like that : 1 N¦öêS‚ `šØ¢¾Œ2 € ...
Qbasic : illegal file number in *line number*
I'm writing a program in GW-BASIC. For some reasons, I have the following error : 'Numéro de fichier illégal en 4712' which can be translated in english by, ' illegal file number in 4712' Here ...
How to test if a directory exist in qbasic?
I'm writing a program in Qbasic. I'd like to know how to test if a folder exists.The idea is:IF 'c:userbasicblablabla' exists (?? how to programm the 'exist' test?)THEN CHDIR 'c:userbasic...
Gw Basic Sample Programs
why is the function CHDIR not working on the network ? Qbasic BasicA
I have a .bas file that I run using GWBASIC.EXEThe .bas file uses other files located in the path : srv120 (T:)Basic(GWBASIC.EXE and the .bas file are also in the same directory TBasic)In the ...
Was there ever a first parameter for the CLEAR statement?
In both GW-BASIC and QuickBASIC, statements are passed arguments, some of which are optional and can be omitted depending on the statement:REM Move the text cursor to the specified column and row....
Modify basic files used with gwbasic
I have a batch file which launches other .bas files with the help of gwbasic.Here is the code of the batch file:graphicscd basicgwbasic menut-hp/dcd Then I have the possibility by typing 1 or ...
Explicit line numbers and execution order
GW-BASIC and many other old BASIC dialects like C64 BASIC allowed you do something like this:20 PRINT 'World'10 PRINT 'Hello' and that would result in the following output when the RUN command/...
How can I exit Microsoft GW-BASIC, IBM BASICA, or other similar old dialects of BASIC?
Microsoft BASIC, GW-BASIC and BASICA all use a prompt that looks like this: I can't figure out how to exit any of these. Typing END does not exit them. EXIT, QUIT, Q, Ctrl+C, and everything else that ...
Print without newline in BASIC
In BASIC I know of two instructions to print to the screen, PRINT and WRITE, both of which automatically print strings with a newline at the end. I want to print a string without a newline. How can I ...
What is the error in following program in GW BASIC?
I was making a program which could tell if a given number is a prime number or not. No matter whether I enter a prime number or another number, it always shows 'it is not a prime number'. Is there any ...
How do I view the source code of a Gwbasic .bas file?
I have an old .bas file that I'm trying to view and running into some problems. Searching online seems to indicate that I should be able to just open it in notepad or simililar, but doing so gives me ...
Nested IF…THEN…ELSE in GW-BASIC
I use following block of code to test some conditions in gw-basic program.IF Average >= 80 AND Average <= 100 THEN Grade$ = 'A'IF Average >= 70 AND Average <= 79 THEN Grade$ = 'B'IF ...
How MKI$ and CVI Functions works
I am working on GwBasic and want to know how 'CVI('aa')' returns '24929' is that converts each char to ASCII but code of 'aa' is 9797.
assigning to arg inside function definition?
Trying to read some old BASIC code to do a port, and coming across this mind-bending concept:1150 DEF FNB(Q)=Q+8*((Q=9)-(Q=0)) What... is going on here? How can you assign to the parameter like ...