general variabile and while loop problem

Ivan
15
Ivan  

Good morning, everybody.

I have a problem that can't understand

int indice = 0; 
int e = 0;

void OnTick(){

        int a = 0;
	string testo = "";

        while(1>0){
                testo += "ciao \n";
   
                a++;
                indice++;
                e++;

                if (e == 1)
                        break;
                if (indice == 2)
                        break;
                if (a == 3)
                	break;   
        }
 Comment(testo);
}

the result is 3 prints. only the variable declared in the function OnTick works. 

I have this problem only with while and do-while loops. I do not have this problem with for-loops.

when i try to remove the variable "a", the loop results in infinity. 

Sardion Maranatha
561
Sardion Maranatha  
8714917:

Good morning, everybody.

I have a problem that can't understand

the result is 3 prints. only the variable declared in the function OnTick works. 

I have this problem only with while and do-while loops. I do not have this problem with for-loops.

when i try to remove the variable "a", the loop results in infinity. 

while(a<3)
Sardion Maranatha
561
Sardion Maranatha  
Ivan:

Good morning, everybody.

I have a problem that can't understand

the result is 3 prints. only the variable declared in the function OnTick works. 

I have this problem only with while and do-while loops. I do not have this problem with for-loops.

when i try to remove the variable "a", the loop results in infinity. 

you forget to reset the global value back to zero after the while condition is met
Ivan
15
Ivan  
Sardion Maranatha:
while(a<3)

 ... ok, try this

int a = 0;

void OnTick(){
   string testo = ""; 
   while(a < 3){
      testo += "ciao \n";
      a++;              
   }
        
   Comment(testo);
}

why is this an infinite loop?

Sardion Maranatha
561
Sardion Maranatha  
Ivan:

 ... ok, try this

why is this an infinite loop?

reset the global value back
Ivan
15
Ivan  

I find the problem, it wasn't the while loop problem

thanks

William Roeder
24189
William Roeder  
Ivan: I find the problem, it wasn't the while loop problem

Don't do that. Someone searching might find this thread and still be clueless. What was the problem? What solved what?

How To Ask Questions The Smart Way. 2004
     When You Ask.
          Follow up with a brief note on the solution.

Sardion Maranatha
561
Sardion Maranatha  
William Roeder:

Don't do that. Someone searching might find this thread and still be clueless. What was the problem? What solved what?

How To Ask Questions The Smart Way. 2004
     When You Ask.
          Follow up with a brief note on the solution.

@Ivan William has a good point, this thread can also help others and he could give other helpful pointers