MS Coding Camp(working title)

This forum is for discussion about anything else.
User avatar
PeregrineV
PeregrineV
Survivor
User avatar
User avatar
PeregrineV
Survivor
Survivor
Posts: 21275
Joined: February 23, 2011
Location: Zendikar

Post Post #75 (ISO) » Thu Jan 05, 2017 5:26 am

Post by PeregrineV »

In post 62, Cheetory6 wrote:Spoiler: While Loops
For the other two control structures, we will be using a similar concept of using boolean expressions to guide the movement of our program, but we’ll adding the concept of Loops/Looping on top. A loop is essentially a section of code that gets repeated in the flow of program’s operation. We will first consider the While loop:

Code: Select all

int i = 0;
while(i < 4){
Debug.Log(i);
i++;
}
Debug.Log(“Escaped!!”);


The basic idea of the while loop, is that while the condition within the brackets is true the code within the curly brackets will repeat.
In this case, the while loop will repeat the code within its curly brackets until the variable i is no longer less than 4.
OUTPUT:
1 - "1"
2 - "2"
3 - "3"
4 - "4"

Code: Select all

int i = 0;
while(i < 4)
{    Debug.Log(i);    i++;}
Debug.Log(“Escaped!!”);

You have to be really careful when using while loops! There is the potential to create a set of conditions where a while loop will never have its condition become true and then the code within will repeat indefinitely and lock up your program. If you remove the contents of the code within the while loop above as follows, you will never get the “Escaped!!” message.
Would the output of the first code batch be

"0"
"1"
"2"
"3"
“Escaped!!”

Since when
i
hits 4 it pops it from the loop?
I will have
Limited Access
on weekends.
User avatar
Frozen Angel
Frozen Angel
She
Queen Shifty
User avatar
User avatar
Frozen Angel
She
Queen Shifty
Queen Shifty
Posts: 18753
Joined: October 26, 2015
Pronoun: She

Post Post #76 (ISO) » Thu Jan 05, 2017 5:28 am

Post by Frozen Angel »

yes

edit : and I believe the second code is the same.
False tears bring pain to those around you
False smile brings pain to one's self


"Frozen Like Your Heart." -Ginngie
Post Reply

Return to “General Discussion”