Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site gitpyr.UUCP Path: utzoo!linus!decvax!harpo!whuxlm!akgua!gatech!gitpyr!tynor From: tynor@gitpyr.UUCP (Steve Tynor) Newsgroups: net.lang Subject: Re: Varieties of conditional statement Message-ID: <871@gitpyr.UUCP> Date: Fri, 11-Oct-85 16:40:26 EDT Article-I.D.: gitpyr.871 Posted: Fri Oct 11 16:40:26 1985 Date-Received: Sat, 12-Oct-85 07:24:14 EDT References: <418@phri.UUCP> <2600012@ccvaxa> <1901@reed.UUCP> <1703@peora.UUCP> Reply-To: tynor@gitpyr.UUCP (Steve Tynor) Organization: Georgia Institute of Technology Lines: 67 In article <1703@peora.UUCP> jer@peora.UUCP (J. Eric Roskos) writes: >The different brace styles actually have their basis in a much more >fundamental, and presently very important, matter having to do with the >design of languages. > >Some languages, such as Pascal and C, define conditional statements (this >includes ifs, whiles, etc) like this: > > > >e.g., > if (x) > >You then have defined recursively as either of a simple >statement, or as a sequence of statements delimited by a begin/end pair. > >However, this style has recently fallen into disfavor. Thus we have the >sort of definition that is in Ada, in which all conditional statements >can contain one or more statements, like this: > > {} > >where the conditional itself is imbedded in the conditional begin. > >Now, I would argue that the latter is a "weaker" construct than the former. >The reason is (among other things) that the which can be a >compound statement can also have private data (and thus is a "block"), >whereas the latter approach requires a separate "block" construct to be >defined if you want to have a local scope of reference (and note that >syntactically, defining a local scope of reference within each type of >conditional is harder since the declarations have to be duplicated >in each conditional type). You're really talking about the semantics of the particular construct, not it's syntax. The syntax of: IF c THEN s ENDIF mearly emphasizes what kind of a statement sequence we're closing. It does not imply any different semantics (such as an inability to declare local variables within the block). Syntactically, there's no reason why we couldn't have something like: IF c THEN DECLARE a : INTEGER; ... ENDIF And personally, I'd prefer it to : IF c { DECLARE a : INTEGER; ... } since nested blocks can really make matching brackets annoyingly difficult. BTW, both Ada and Modula-2 require special end-markers at the end of procedure and module(package) bodies too. (end procedure_name;) This is a great help in program readability, just as the end-if, end-while are. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= No problem is so formidable that you can't just walk away from it. Steve Tynor Georgia Instutute of Technology ...{akgua, allegra, amd, harpo, hplabs, ihnp4, masscomp, ut-ngp, rlgvax, sb1, uf-cgrl, unmvax, ut-sally} !gatech!gitpyr!tynor