LoginLogin

Loops

Root / Submissions / [.]

DefaultioCreated:
The three different types of loops are: -Goto = Infinte time loop or just to get somewhere in the code and continue code -Gosub = To go somewhere in the code and then return back to the place gosub was initiated - For,to,step = Allows limited number of times, a certain instruction can play for

GOTO

The GOTO command allows you to GO somewhere in your code with an @label. GOTO @(insert name of label here for goto to "goto") Example :
 ACLS
@Loop
PRINT "Hi"
WAIT 60
GOTO @loop
The result is a screen that has "Hi" just infinitely going down on your screen, until you stop the program. The GOTO command reads the @loop and searches for that one specific label and then continues the code like normal from there. You have to have an @(any name here, it's a label) for GOTO to work, or it will give you an error. Simple.

GOSUB

The GOSUB command allows you to GO into a SUB loop and then return with the RETURN command. Example :
 ACLS
@Loop
PRINT "Hi"
WAIT 60
GOSUB @SLoop
PRINT "Success!"

@SLoop
CLS
WAIT 30
PRINT "If you see this, then it worked!"
WAIT 30
RETURN

Okay, let me break this down. Basically it's the same code from the GOTO command, but I added GOSUB instead of GOTO. When GOSUB was implemented, it has the same characteristics as GOTO but you have to put a RETURN command at the end of the loop. Since it has the same characteristics as GOTO (searches for label and executes code), you don't really need to do much. The thing is though it wont be able to continue your code forever, you need to add RETURN to make it return to the next line of code GOSUB was implemented.

FOR, TO and STEP

This is also part of the looping family, too! The FOR command allows you to loop a certain "thing" to loop for a certain amount of loops. STEP is for counting on how many levels, for example, counting by 5's or 10's. FOR (any variable here>=<any number here to start the loop) TO (any number here to end the loop) (optional) STEP (any number here you want the numbers to count by) Example :
 ACLS
FOR I=0 TO 10
PRINT I
NEXT
What this outputs to the run mode, is FOR I=0, I is starting at 0, TO 10, and should end at 10. What it should put on the direct mode, is:
1
2
3
4
5
6
7
8
9
10
If you add step however :
 ACLS
FOR I=0 TO 10 STEP 5
PRINT I
NEXT
It'll start counting by fives until it reaches near or at it's goal.
0
5
10

WHILE

Repeats the process up to WEND while the condition is satisfied - Exits the loop if the condition is not satisfied or when the BREAK instruction is executed Format WHILE Conditional expression Conditional Expressions The same conditional expressions as in IF statements can be specified Comparison Operators == Equal to != Not equal to > Greater than < Smaller than >= Equal to or greater than <= Equal to or smaller than Logical operators (for comparison with multiple conditions) (Condition 1 AND Condition 2) Both of the two conditions must be satisfied (Condition 1 && Condition 2) Both of the two conditions must be satisfied (Condition 1 OR Condition 2) Either of the two conditions must be satisfied (Condition 1 || Condition 2) Either of the two conditions must be satisfied * The key "||" can be found to the upper left of ? on your keyboard. Example A=0:B=4 WHILE A<B A=A+1 WEND

WEND

Instruction that indicates the end of a WHILE loop Format WEND Example A=0:B=4 WHILE A<B A=A+1 WEND

REPEAT

Instruction for starting a REPEAT loop - The UNTIL instruction and a conditional expression should be placed at the end of the loop - Unlike the WHILE instruction, this executes the process before determining the condition - Exits the loop when the condition is satisfied or when the BREAK instruction is executed Format REPEAT Example A=0:B=4 REPEAT A=A+1 UNTIL A>B

UNTIL

Repeats the process from REPEAT until the conditional expression is satisfied - The REPEAT instruction should be placed at the beginning of the loop - Unlike the WHILE instruction, this executes the process before determining the condition - Exits the loop if the condition is satisfied or when the BREAK instruction is executed Format UNTIL conditional expression Conditional Expressions The same conditional expressions as in IF statements can be specified Comparison Operators == Equal to != Not equal to > Greater than < Smaller than >= Equal to or greater than <= Equal to or smaller than Logical operators (for comparison with multiple conditions) (Condition 1 AND Condition 2) Both of the two conditions must be satisfied (Condition 1 && Condition 2) Both of the two conditions must be satisfied (Condition 1 OR Condition 2) Either of the two conditions must be satisfied (Condition 1 || Condition 2) Either of the two conditions must be satisfied * The key for "||" can be found on the upper left of ? on your keyboard. Example A=0:B=4 REPEAT A=A+1 UNTIL A<B That's pretty much it guys, I hope you liked it! I hope it wasn't too confusing for you new guys!

Add the While and Repeat looptypes up at the top.

Replying to:chicken
Add the While and Repeat looptypes up at the top.
Why? It's not a beginners loop.

Replying to:chicken
Add the While and Repeat looptypes up at the top.
The three different types of loops are:

Replying to:chicken
Add the While and Repeat looptypes up at the top.
Shush now, i was too lazy to edit it. Also I forgot about the rest of my page.

WHILE 1...WEND should be used in place of @LOOP ... GOTO @LOOP Since most loops have a way of ending, you can do WHILE !(end condition) ... WEND Or you can use repeat, which is better for that situation: REPEAT ... UNTIL end condition

Replying to:chicken
Add the While and Repeat looptypes up at the top.
WHILE 1...WEND is the most beginner-ish loop possible.

Good tutorial for beginners. Literally thank you, Hopefully there will be less PEOPLE BEGGING OTHERS TO MAKE A GAME FOR THEM!

The three different types of loops are: GOSUB is not a loop, and the list does not include WHILE or REPEAT.