CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for bool
2009 |
Submission reference: IN1810
How do you compare BOOLs, say in an IF statement? For example, if I have:
INITIAL BOOL b IS TRUE: SEQ ... code where the value of b can change IF b = TRUE -- This always says "expected "?", found end of line" ... do something
Can you tell me what I'm doing wrong?
There is nothing wrong with your code fragment about which the compiler should complain ... unless within the hidden code "where the value of b can change", b is acttually re-declared as a channel! Please mail your seminar leader the whole code if your problem has not disappeared.
However, there is something about your code that is a bit weak. The condition(s) associated with an IF are, of course, BOOL(s). In your code, b is a BOOL (unless re-declared as something else!). Assuming it is a BOOL, then the expression:
b = TRUE
is a clumsy way of saying:
b
So, your code would be much neater as:
INITIAL BOOL b IS TRUE: SEQ ... code where the value of b can change IF b ... do something
Last thought: your IF sturcture had better have some more conditions in case b turns out to be FALSE. Otherwise, there will be a run-time error – see Question 2 (2006) and Question 46 (2000).
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |