while: wend - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: while: wend (/showthread.php?tid=1361) |
while: wend - fistfullofnails - 01-03-2023 On Terry Ritchie's function/subroutine part of the QB64 tutorial, line 15 of subs.base, we have: Code: (Select All) WHILE _MOUSEINPUT: WEND The only way I've seen "WHILE" and "WEND" used is at the start and end of a loop, with some instructions in between, which then ends with 'WEND". I'm confused on what is exactly going on here. Can anyone explain like I'm a five year old? Code: (Select All) DO RE: while: wend - SMcNeill - 01-03-2023 WHILE _MOUSEINPUT: WEND While.... there's input in the mouse update buffer Repeat It basically clears and updates the mouse buffers so you're getting the current mouse status rather than some backlog of past X/Y positions which doesn't mean anything to you anymore. RE: while: wend - mnrvovrfc - 01-03-2023 "WHILE... WEND" was the only provided way by GW-BASIC to do loops without relying on "GOSUB/RETURN" and "GOTO". "DO... LOOP" is superior, I had first seen it in Commodore 128 BASIC, in "RUN" magazine. This game I wanted badly on my Tandy1000HX LOL back in the late 1980's. Some guy wrote a book about programming in QuickBASIC, said "WHILE... WEND" was acceptable and otherwise "GOTO" with clear labels, and "DO... LOOP" was too much like Pascal and he didn't like it. To try to make the older construct more useful "EXIT WHILE" was added. That's why now we also have "EXIT SELECT" which is sloppy also. QuickBASIC didn't have "EXIT WHILE" nor "_CONTINUE", and therefore the only way to create a "run-once" loop was to employ a "DO... LOOP" that purposely fell through at the end such as "LOOP WHILE 0" or "LOOP UNTIL 1". The idea was to be able to use "EXIT DO" to skip a bunch of lines within the false loop according to a condition. See the Wiki example for "DO... LOOP" which I think was one of the most useful to me. https://qb64phoenix.com/qb64wiki/index.php/DO...LOOP (Example #3) RE: while: wend - bplus - 01-03-2023 "WHILE... WEND" was the only provided way by GW-BASIC to do loops without relying on "GOSUB/RETURN" and "GOTO". Nope! For... Next was in there first even before While... Wend Dartmouth BASIC - Wikipededia Quote:List of BASIC statements RE: while: wend - bplus - 01-03-2023 This use to be THE WAY to pause a program waiting for a key press. Code: (Select All) Print "We will pause until you press some key..." Now days there are better ways unless you want to blow the dust off your CPU fan. RE: while: wend - james2464 - 01-03-2023 "ELI5" attempt: I was confused by this as well. WHILE _MOUSEINPUT: WEND looked like a single line of code to me. The : symbol is used to separate lines of code on the same line. An example would be... FOR t = 1 TO 10 : NEXT t If you forget that and just think of it as two lines... WHILE _MOUSEINPUT WEND Then you can just consider reply #2. But that was also confusing to me a while ago. I wondered how this doesn't just loop infinitely. But it just goes and checks for the latest mouse input and then exits the loop. RE: while: wend - mnrvovrfc - 01-03-2023 (01-03-2023, 03:39 PM)bplus Wrote: "WHILE... WEND" was the only provided way by GW-BASIC to do loops without relying on "GOSUB/RETURN" and "GOTO". Nobody was going to use a "FOR... NEXT" loop to create what looked like an infinite loop. I stand corrected, because some people forced a much longer loop than was set in "FOR" statement by simply setting the loop variable so it never reached the destination... This creates an endless loop: Code: (Select All) FOR t = 1 to 10 Also "FOR... NEXT" always required a variable, although breaking out of an endless "WHILE... WEND" needed to test something. Anyway I was trying to emphasize that "DO... LOOP" was presented later as an alternative away from 8-bit computers having BASIC interpreters. RE: while: wend - Kernelpanic - 01-03-2023 If "wend" one go down, "while" can not go up! -- Where is the problem? RE: while: wend - TempodiBasic - 01-04-2023 just right Code: (Select All) 10 Rem while RE: while: wend - bplus - 01-04-2023 Here's how to do _MouseInput without While...Wend but just a GOTO. A one liner like While _MouseInput :Wend and without double parking (2 statements separated with colon). Code: (Select All) _Title "Click to draw paths from one click to next" 'b+ 2023-01-03 EDIT: No sooner had I posted this when I realized the 2nd GOTO was not needed. Cool! Looks like TempodiBasic was kinda close ;-)) |