LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Guide to loops

Root / Submissions / [.]

randoCreated:
Ah, loops, so useful, so many! Here I will show you how to use different loops. Now lets go over the types:
  • @loop
  • Repeat loop
  • while loop
  • for loop
Lets start now! @Loop Ok I DONT recomend this one, it is less efficient, but that doesnt really matter now. You can have a loop that looks like this:
ACLS
@LOOP
'Some code
WAIT 1
GOTO@LOOP
Thats basically it, but this is not a recommended loop. Repeat loop Yes, a repeat loop. This one is basically (bad pun) a loop that repeats until the specified condition(s) is/are satisfied. Ex:
ACLS
REPEAT
'Some code
UNTIL 'Condition that should be satisfied
So theres that. While loop This is basically (again) the repeat loop reversed, while a condition is satisfied, it loops. Here is an example:
ACLS
WHILE 'Conition that is satisfied
'Some code
WEND
so thats that. For loop This one is kinda useful, like for loading maps, but basically (AGAIN) is a loop where a variable is equal to a value and the loop repeats until the variable is equal to an other value. I dont think you can change the value while its looping, but when it loops the value increases/decreases depending on if the value is bigger or smaller than the other value until it is equal to the other value. it then stops looping and the value is still equal to the second value. Also if you put STEP then a number, it will change the amount that the variable is changing by, by the number after step. eg:
ACLS
FOR I=0 TO 3
'Some code
NEXT
ACLS
FOR I=0 TO 4 STEP 2
'Some code
WEND
additional stuffAlso with the while/repeat loops u can do this for infinint looping. remember they are different:
ACLS
WHILE 1'This!
'Some code
WEND
ACLS
REPEAT
'Some code
UNTIL 0'Here!
bananaโ†“โ†“โ†“

STEP is the amount to increase the FOR variable by each time

ACLS
REPEAT
'Some code
UNTIL 0'Here!
(loops forever)
I've been using UNTIL 1==0 for infinite FOR loops

Replying to:12Me21
STEP is the amount to increase the FOR variable by each time
thx, ill add that. also doesnt it decrease if its like
FOR I=3 TO 0
?

Replying to:12Me21
STEP is the amount to increase the FOR variable by each time
it always adds 1 if you don't use STEP. you have to set the step to a negative number if you're going backwards.

Replying to:IAmRalsei
ACLS
REPEAT
'Some code
UNTIL 0'Here!
(loops forever)
I've been using UNTIL 1==0 for infinite FOR loops
You don't even need to do that. Just use UNTIL 0. One less computation per loop.

Replying to:IAmRalsei
ACLS
REPEAT
'Some code
UNTIL 0'Here!
(loops forever)
I've been using UNTIL 1==0 for infinite FOR loops
i learned that right before i posted this didn't you see the quote?