Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

While loop always true CCS

Writer Emily Wong

I'm using CCS compiler and for this piece of code getting a warning that condition is always true. This is a code for PIC16F877, so when the input is 1 , it should break out of loop. Am I missing something here?

int read_keypad()
{ int value=0; while(1) { UpButton=0; // In case of bad Input DownButton=0; RightButton=0; LeftButton=0; EnterButton=0; output_high(sat1); if (input(sut1)) { value=1; while(input(sut1)); break; }
}

1 Answer

The loop condition is always true. That warning does not mean that your loop could not possibly exit, just not through its test condition.

When input(sut1) returns true you are entering a loop that does nothing until input returns false, then you are breaking out of your outer loop and exiting read_keypad()

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.