Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed for while loop!!!

Status
Not open for further replies.

sergelaurent

Technical User
May 30, 2005
52
0
0
FR
I have the following code

while(1) {
if(toto==1) {
....
} elseif(toto==2) {
...
}
}

toto is a globlal variable.
I have noticed that if I initialise toto to 0 at the start of my program and when I set it to 1 later, the change in the value of toto is not refreshed in my while loop.
So, I wanted to know how to refresh the value of toto continuously or every periood time in my while loop?
 
It's impossible behaviour (with undefined notion of value refreshing). But in this case (as in a snippet above) you never set toto to 1 because of there are only toto==1 and toto==2 (skipped) branches in the loop with initial value of toto==0. So you have and idle loop forever...
What is it refresh the value in your case? Have you any refreshing thread or what else?
 
> So, I wanted to know how to refresh the value of toto continuously or every periood time in my while loop?
The short answer is find a better way of solving the problem.

The quick answer is to say
Code:
volatile int toto = 0;
Then, whenever you modify the variable 'from outside', then loop will immediately pick up the change.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top