#21✎ 187seggiepantsYes, you can use vsync just about anywhere in your code. While is just a better type of loop.
#22✎ 136VakoreAre there any speed bonuses of using a while loop?
#23✎ 203niconiiVideo GamesI like to play video games!HobbiesExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthDrawingI like to draw!Hobbies
Can you use vsync in a while loop?
'code goes here
'code goes here
Both 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?
Nope. At least, it shouldn't be anything significant.
Actually, based on my tests in SB4, a while loop seems to be the slowest way to do an infinite loop, actually. I guess it makes sense, since it has to evaluate an expression every loop iteration.
#24✎ 136VakoreOk, thanksniconni. I of course seggiepants is going to interject, so I'll wait for that to see his thoughts.
#25✎ 46incvoidThanks 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
#26✎ 187seggiepantsIf 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.
#27✎ 136VakoreOk. I'm not new to coding, so I'll stick to GOTO. About. Neatness though... if I used an actual keyboard, it would be super neat, but since I have to type with a stylus, I'm now being super neat(though I do try to organize the code)
#28✎ 183412Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfMore importantly: please indent your code lol
#29✎ 136VakoreI indent where it matters. Can someone please close this thread as the issue has been solved.