LoginLogin
Might make SBS readonly: thread

Label Loops

Root / Submissions / [.]

chickenCreated:

NEVER USE THESE.

@LOOP
 'CODE
GOTO @LOOP
@LOOP
 GCLS
 GOSUB @GAME
 GOSUB @RENDER
 WAIT 1
GOTO @LOOP

@GAME
 'CODE
RETURN

@RENDER
 'CODE
RETURN

Replying to:rando
fun fact you NEED to use for loops to load a map on screen, at least of what i know, ex:
FOR I=0 TO 3
BGSCREEN I,127,128'(or I,64,64)
NEXT
/the rest of map loading code
no i meant speed in basic, idiot also basic and lua are the only programming languages i know

Replying to:rando
fun fact you NEED to use for loops to load a map on screen, at least of what i know, ex:
FOR I=0 TO 3
BGSCREEN I,127,128'(or I,64,64)
NEXT
/the rest of map loading code
it was an extreme example and it was sarcastic.

Fun fact: REPEAT loops exist too. They loop until an contidion is satisfied.

Replying to:kitesinpowerlines
I agree and disagree. I think GOTO loops are nice for beginners to understand how loops work (especially if they have no programming experience). With that being said, once you have the basics down it is time to abandon label loops, otherwise you will not grow as a programmer beyond the "beginner" levels.
Faster isn't always ideal, especially if it is only milliseconds. But hey, you can continue using your GOTO loops and I'll continue to not play any of your programs because we all know you aren't producing quality games or resources judging by the ratings of your submissions. Perhaps if you took the time to learn about other ways to program you may be able to put something out that worth the attention it receives.

Replying to:kitesinpowerlines
I agree and disagree. I think GOTO loops are nice for beginners to understand how loops work (especially if they have no programming experience). With that being said, once you have the basics down it is time to abandon label loops, otherwise you will not grow as a programmer beyond the "beginner" levels.
Look, no one has hit a point where GOTO is really important yet AFAIK, and I don't think you need to use it unless you're trying to write CS:GO in SB (which isn't even technically possible). Stop taking my comments out of context, and just accept that GOTO is not a good alternative to WHILE, FOR, REPEAT, or other better loops unless you are 101% sure that your game will not work properly with proper loops. I highly doubt that you NEED to use it especially at the skill level you're at right now.

Maybe you should suggest an alternative rather than just telling people not to do something. I'm pretty sure there are already like 10 pages for WHILE/REPEAT loops though.

Replying to:12Me21
Maybe you should suggest an alternative rather than just telling people not to do something. I'm pretty sure there are already like 10 pages for WHILE/REPEAT loops though.
I think the idea was to make an explanation for Label use examples and the comment made it in there for obvious reasons

Replying to:MochaProbably
Fun fact: REPEAT loops exist too. They loop until an contidion is satisfied.
Basically while but checks condition after an iteration not before.

I like how something so obvious managed to get chicken the “good page” badge.

Replying to:ProKuku
I like how something so obvious managed to get chicken the “good page” badge.
Actually, it was https://smilebasicsource.com/page?pid=698 that did. This one is too controversial; 'Good page' requires a certain ratio of upvotes to downvotes.

Replying to:kitesinpowerlines
I agree and disagree. I think GOTO loops are nice for beginners to understand how loops work (especially if they have no programming experience). With that being said, once you have the basics down it is time to abandon label loops, otherwise you will not grow as a programmer beyond the "beginner" levels.
Saying "milliseconds" is quite an exaggeration. The difference is only that big after a few thousand/million passes through the loop.

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
Well, REPEAT/WHILE/FOR/GOTO loops are all as fast as each other (in my opinion).
...Although for code & size improvements I would replace any loop with a FOR loop if the content should happen a certain amount. REPEAT could be used for this too. WHILE is perfect for an ∞ loop. But each one is not faster than the other.

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
GOTO is a few milliseconds faster than the other ones

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
Fortunately,
"GOTO"
@LOOP
REM Do something
INC X
IF X<9 THEN GOTO @LOOP
Better wayEither:
FOR X=0 TO 9
REM Do something
NEXT
Or:
REPEAT
REM Do something
INC X
UNTIL X==9
Speed = is the same on each type Readability (for new SB users) = GOTO isn't a good idea Size in programs = GOTO takes more space than WHILE/FOR/REPEAT My conclusion = GOTO is not recommended (especially for unskilled programmers/new SB users).

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
GOTO is only faster by a few milliseconds because it doesn't have to check if something's true or change a variable. When you add in the cost of checking if something is true before continuing a GOTO loop, GOTO may actually be worse... also it looks awful. [citation needed] With WHILE and FOR, everything is clearly labelled as "yep, this is the thing getting checked for every loop," or "hey, this is the variable that goes up every loop." Also, GOTO breaks variable scoping, which is a very useful tool if you know how to use it.

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
FOR is faster than GOTO.

Replying to:MasterR3C0RD
There's nothing inherently wrong with using label loops, but it's better to use WHILE, FOR, REPEAT, etc unless you need to make sure your program runs as fast as possible, since label loops don't prepare you for other programming languages in the future, and usually you don't need to squeeze every bit of speed out of your code in SB so
i think it doesn't matter which one at all. i still recomend not goto, but it doesn't matter all that much.