Hi friends; how can I return with new i value to "while loop" ? and while loop will go on with new i value...I am reading new i value from external interrupt... as an example;
====================
x=50;
i=0;
void loop()
{
while(i<x)
{
i=i+1;
}
}
void external_interrupt()
{
i=5;
}
====================
// think that; when i=20 in the loop, external interrupt occured. as you see i=5 in interrupt. I want to return i=5 to while loop and while loop will continue to count (i=i+1) like i=5... in brief, while loop will go on with new i value.
why I need this;
in my orijinal code, i value is calculating when interrupt occurs and I must return with calculated i value to the while loop. But it does not work 
thanks for your help...
The actual declaration of "i" is missing. It should, however, be declared as volatile.
You cannot return a value from an ISR but you can change the value of a volatile global variable within it
Your mention returning to the while loop, but bear in mind that the interrupt could occur at any time and not just in the while loop unless you explicitly disable and enable interrupts in other areas of the code.
i had issue like this yesterday where I set a variable for do while to break the do_while but only the one at the bottom of the loop worked. the one in the middle didn't seem to work.
When using a do/while the condition is only checked at the end of the loop after all the commands in the loop have been executed
When using a while loop it is only checked at the start of the loop before any of the commands in the loop are executed
You can, of course, cause either type of loop to terminate early by using the break; command
What if i==x before the interrupt happens (or even worse, in the middle of a compare if i is a multibyte variable)?
If your main loop is checking a multibyte variable that an interrupt has modified you will have to disable interrupts while you make a temporary copy. If your variable needs to support values greater than 255 then you will have to use a multibyte variable.
In any case you have to use the 'volatile' keyword when declaring variables shared by your interrupt and main loop.