Hello, SMALL Basic programmer, welcome.
Beside, nested loop and not-nested loop, loop can also be defined into forever loop and not-forever loop.
So, based on the mechanic, loops can also divided into:
1. Nested loop
2. Not-nested loop
And, types of loop based on lifetime:
1. Forever
2. Not-forever or limited
So, in this tutorial we will learned with not-nested loop, forever loop and not-nested loop, not-forever loop.
You know, there are 2 types of loop based on lifetime. Forever loop and not-forever loop. And, there are 3 types of loop maker: For, while and if.. goto..
3 Loop maker:
1. For
2. While
3. If.. Goto..
2 Types of loop based on lifetime:
1. Forever
2. Not-forever or limited
Both can be made with loop maker.
For example:
1. Forever
1.1 Forever loop with For loop
You can make forever loop using for by using a very,very big number. So it looks like forever because of length of the number, but it is not.
for i = 0 To 9999999999999999999999999
TextWindow.WriteLine(i)
EndFor
1.2. Forever loop with While loop
You can also make forever loop by using while loop by using a very, very big number, so it also looks like forever because of length of the number, but it is not.
While i < 999999999999999999999999999
TextWindow.WriteLine(i)
i = i + 1
EndWhile
1.3. Forever loop with If.. Goto.. Loop
This the last type and actually it is the best kind of making forever loop.
up:
TextWindow.WriteLine(i)
i = i + 1
Goto up
2. Not-forever
2.1 Not-forever loop with For loop
Creating not-forever loop with for loop is easy, you just need to define the number not big enough as the limit.
Example:
For i = 0 To 100
TextWindow.WriteLine(i)
EndFor
2.2 Not-forever loop with While loop
Creating not-forever loop with While loop is easy, the same as For loop, you just need to define the number that is not big enough as the limit.
For example like below:
while i < 100
TextWindow.WriteLine(i)
i = i + 1
EndWhile
2.3 Not-forever with If.. Goto.. Loop
Okay, to make not-forever loop or limited loop with If.. Goto.. Loop is quite difficult. But it is okay, you will got it.
In this, if.. goto.. loop type you will need the help of iterator variable (in this case i variable), same as with While loop example and off course, you need the help of a label to jump to.
So, iterator variable, the increments expression for iterator, goto expression and a label.
For example
up:
TextWindow.WriteLine(i)
If i < 100 Then
i = i + 1
Goto up
EndIf
Beside, nested loop and not-nested loop, loop can also be defined into forever loop and not-forever loop.
So, based on the mechanic, loops can also divided into:
1. Nested loop
2. Not-nested loop
And, types of loop based on lifetime:
1. Forever
2. Not-forever or limited
So, in this tutorial we will learned with not-nested loop, forever loop and not-nested loop, not-forever loop.
You know, there are 2 types of loop based on lifetime. Forever loop and not-forever loop. And, there are 3 types of loop maker: For, while and if.. goto..
3 Loop maker:
1. For
2. While
3. If.. Goto..
2 Types of loop based on lifetime:
1. Forever
2. Not-forever or limited
Both can be made with loop maker.
For example:
1. Forever
1.1 Forever loop with For loop
You can make forever loop using for by using a very,very big number. So it looks like forever because of length of the number, but it is not.
for i = 0 To 9999999999999999999999999
TextWindow.WriteLine(i)
EndFor
1.2. Forever loop with While loop
You can also make forever loop by using while loop by using a very, very big number, so it also looks like forever because of length of the number, but it is not.
While i < 999999999999999999999999999
TextWindow.WriteLine(i)
i = i + 1
EndWhile
1.3. Forever loop with If.. Goto.. Loop
This the last type and actually it is the best kind of making forever loop.
up:
TextWindow.WriteLine(i)
i = i + 1
Goto up
2. Not-forever
2.1 Not-forever loop with For loop
Creating not-forever loop with for loop is easy, you just need to define the number not big enough as the limit.
Example:
For i = 0 To 100
TextWindow.WriteLine(i)
EndFor
2.2 Not-forever loop with While loop
Creating not-forever loop with While loop is easy, the same as For loop, you just need to define the number that is not big enough as the limit.
For example like below:
while i < 100
TextWindow.WriteLine(i)
i = i + 1
EndWhile
2.3 Not-forever with If.. Goto.. Loop
Okay, to make not-forever loop or limited loop with If.. Goto.. Loop is quite difficult. But it is okay, you will got it.
In this, if.. goto.. loop type you will need the help of iterator variable (in this case i variable), same as with While loop example and off course, you need the help of a label to jump to.
So, iterator variable, the increments expression for iterator, goto expression and a label.
For example
up:
TextWindow.WriteLine(i)
If i < 100 Then
i = i + 1
Goto up
EndIf
Tidak ada komentar:
Posting Komentar