Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!agate!ucbvax!UM.CC.UMICH.EDU!Paul_Abrahams%Wayne-MTS From: Paul_Abrahams%Wayne-MTS@UM.CC.UMICH.EDU Newsgroups: comp.lang.icon Subject: Usage of break Message-ID: <285847@Wayne-MTS> Date: 16 Jan 91 17:04:10 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 34 Today I ran into the kind of problem I'm sure most of us have now and then: a single line in an Icon program whose behavior I just couldn't understand. What I wrote was: repeat{ ... until find("\\syntax", read(infile) | break) ... } The idea was to read lines until I found one containing `\syntax' or the file was exhausted. (I intended to throw out the `\syntax' line; I was only interested in what followed it.) I couldn't understand why the expression was exiting immediately. What I finally realized was that in the constructs while expr1 do expr2 and until expr1 do expr2 a `break' in expr1 terminates the construct in the same way as if it's in expr2. I read page 19 of the Icon book fairly carefully, but not carefully enough; it says that a break expression causes immediate termination of the loop in which it occurs. I had thought that `the loop' was just expr2, but in fact it includes expr1 as well. So the failure of `find' provoked the evaluation of `break' ~(as a result of goal-directed evaluation) and therefore the termination of the expression each time a line was read. I do understand now what's going on, and it does make sense---but it isn't what I initially expected. Paul Abrahams abrahams%wayne-mts@um.cc.umich.edu