View previous topic :: View next topic |
Author |
Message |
wahid
Joined: 02 May 2013 Posts: 5
|
while |
Posted: Fri May 03, 2013 6:16 pm |
|
|
I have a question PIC C compile.
how to exit the while loop condition because the break problem unconditionally |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri May 03, 2013 6:28 pm |
|
|
sorry, but this does not make sense for me.
break;
IS the unconditional way out of while
if (condition) break;
is the conditional way.
also return;
IF you not in main(); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat May 04, 2013 3:25 am |
|
|
This is actually nothing to do with 'PIC C', but is just standard C...
You have three things in a while loop.
First, the standard 'exit' condition evaluated each time the loop executes.
Then 'continue', which forces this evaluation to occur immediately.
Finally 'break' which exits the loop without testing the exit condition.
Both continue, and break, can themselves be executed with a test.
You have already been given examples of using 'break' with tests. The other method is using 'continue', so:
Code: |
int1 loop=TRUE;
while (loop)
{
//do what you want
if (some exit condition)
{
loop=FALSE;
continue;
}
//and more of what you want
}
|
Here, a 'test' changes the looping condition to 'FALSE', and forces an immediate re-test of the loop condition.
Best Wishes |
|
|
wahid
Joined: 02 May 2013 Posts: 5
|
|
Posted: Sat May 04, 2013 9:44 am |
|
|
my problem I use a 4 * 4 keypad and display. Each button has a function and this function when the data REGARDLESS while loop and complaint in this button.
example temperature value button button to happiness |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat May 04, 2013 11:30 am |
|
|
then post that code and lets look at it's structure. |
|
|
wahid
Joined: 02 May 2013 Posts: 5
|
|
Posted: Sat May 04, 2013 6:32 pm |
|
|
such as phone button click button gives 3la result on screen when button function with while
when I click given function but when I click has another button without complaint while not.
thank you |
|
|
|