Yes, you can use vsync just about anywhere in your code. While is just a better type of loop.
Raycaster glitching
Root / Programming Questions / [.]
VakoreCreated:
Can you use vsync in a while loop?
WHILE TRUE 'code goes here WEND @LOOP 'code goes here GOTO @LOOPBoth of these do exactly the same thing, so everything will still work in both of them. Pick whichever one you like better.
Are there any speed bonuses of using a while loop?
Thanks for the spchr advice.
I think labels and goto are fine if ya dont have any conditions to exit the loop.
I wish there was a version of vsync that held until the next refresh..frame skipping... i think tearing still occurs if ya take too long to update... maybe im just using it wrong.
I always thought to draw to offscreen, vsync, flip offscreen and onscreen, or would it be better to flip then vsync? Oh well
If you are comparing speed, then GOTO ought to be the fastest. Whether you could ever notice the speed difference in a real program is unlikely.
Not using GOTO is about hygiene, structure, reusablity, and readability. Using GOTO encourages several bad habits that tend to turn your program from a concrete structure into a tangled mess. Or as it is normally known spaghetti code.
Functions get local variables, goto makes you rely on largely only global variables. Local variables are better because you have less dependencies throughout your code.
While, For, and Repeat loops all have a definite markings of where they begin and end. Goto can jump in the middle of a loop from anywhere. This makes things much harder to predict, read and maintain.
Most of the coders here are just starting out (even if they class themselves as experts, they are largely still novices). GOTO is a really BAD habit that teaches you to code poorly. It doesn't scale to hundreds of lines of code let alone more, and can make intractable messes. Messes that make novices give up in frustration. So there is also an ounce of prevention being better than a pound of cure thing going on as well as a don't make people give up before they ever get started.
Most languages don't even include it anymore since it is so easily abused.
I've gone over this at length before only to be called names by admins. If you want to read more you can look at my old posts or just search the web for a neutral third party opinion. I don't really want to write a novel on it, I have already gone on too long.