? Guide to loops ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Guide to loops

Ah, loops, so useful, so many! Here I will show you how to use different loops. Now lets go over the types:
  1. @loop
  2. Repeat loop
  3. while loop
  4. 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 [email protected] 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 Also 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↓↓↓
Author
random_god
Updated
Rating
1 vote
Categories
Keywords
6 Comment(s) IAmRalsei IAmRalsei Video Games I like to play video games! Hobbies First Year My account is over 1 year old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
ACLS REPEAT 'Some code UNTIL 0'Here! (loops forever)
I've been using UNTIL 1==0 for infinite FOR loops
JustGreat JustGreat First Month Joined in the very first month of SmileBASIC Source Website Avatar Taboo I didn't change my avatar for 180 days Website Night Person I like the quiet night and sleep late. Express Yourself You don't even need to do that. Just use UNTIL 0. One less computation per loop. IAmRalsei IAmRalsei Video Games I like to play video games! Hobbies First Year My account is over 1 year old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength i learned that right before i posted this didn't you see the quote?
12Me21 12Me21 Head Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website STEP is the amount to increase the FOR variable by each time random_god random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies thx, ill add that. also doesnt it decrease if its like FOR I=3 TO 0 ? 12Me21 12Me21 Head Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website 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.