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 loops
2010 | 
Submission reference: IN1958
Hi, Just wondering if there is an occam-pi alternative to the Java/C continue inside a while loop? For the mars assessment, I have sent an operator response and no longer want to continue with the rest of the code in that iteration of the loop. Thanks in advance :-)
Nope – continue statements are evil and lead to tears. Set a BOOL flag when you send to the operator and use an IF construct to skip the rest of the code. That's explicit and we can see what's happening.
Keywords: continue , break , loops , mars
2000 | 
Example:
  PROC whyowhyOccam(CHAN OF whatever.....)
    BOOL b:
    SEQ
      b:=TRUE
      WHILE b
         ... Code
         IF
           occam = bad
             .. b:=false
           TRUE
             .. More code
  :
With this program, when occam does equal bad :), then b is set to false. Does this mean that the WHILE-loop wiill terminate or does something else happen? When I run it, the WHILE-loop will not terminate when occam equals bad.
Your code has indentation errors and a missing SEQ ... and I'm not sure what your:
             .. b:=false
means? Might you be doing something in the dots that sets b true again? If your code really is this:
  PROC whyowhyOccam (CHAN OF whatever.....)
    BOOL b:
    ...  declarations of your variables occam and bad
    SEQ
      b := TRUE
      WHILE b
        SEQ
          ...  code that sets occam and/or bad
          IF
            occam = bad
              SEQ
                b := FALSE
                ...  something that doesn't change b
            TRUE
              ...  more code
  :
then if occam equals bad inside the loop, the loop will terminate - promise!
Keywords: loops
| 
			
			
			 
			This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.  |