Meta tags:
Headings (most frequently used words):
loop, control, branch, condition, and, handling, early, exit, flow, contents, structure, see, also, references, external, links, sequences, labels, blocks, functions, branches, loops, non, local, jump, conditional, multiway, numeric, controlled, enumeration, infinite, half, problem, unstructured, variants, invariants, sublanguage, system, cross, reference, table, exception, continuation, generator, coroutine, comefrom, event, based, from, nested, middle, test, multi, level, breaks,
Text of the page (most frequently used words):
the (321), yes (139), loop (134), and (103), #control (84), for (79), statement (53), that (53), nested (52), code (51), with (50), example (50), deep (44), from (43), edit (43), programming (41), flow (36), this (36), languages (34), can (34), not (33), language (31), while (31), are (29), condition (28), when (26), then (25), which (25), some (23), articles (22), exit (22), test (22), exception (21), point (21), case (21), iteration (20), retrieved (20), statements (20), level (20), program (19), loops (19), break (19), such (19), goto (18), structure (18), used (18), jump (18), one (18), end (18), may (17), computer (17), execution (17), fortran (16), following (16), xxx (16), early (16), comefrom (16), breaks (16), was (15), has (15), infinite (15), label (15), jumps (15), constructs (14), many (14), value (14), other (14), else (14), python (13), structured (13), also (13), executed (13), but (13), function (13), conditional (13), command (13), using (12), common (12), after (12), line (12), table (11), use (11), foreach (11), first (11), called (11), ruby (10), pdf (10), archived (10), 1974 (10), generator (10), handling (10), continuation (10), stream (10), only (10), multi (10), body (10), perl (9), lisp (9), java (9), where (9), knuth (9), general (9), item (9), similar (9), action (9), construct (9), based (9), there (9), instead (9), return (9), try (9), most (9), numeric (9), done (9), part (9), branch (9), non (8), pascal (8), ada (8), original (8), all (8), does (8), half (8), 2020 (8), print (8), any (8), than (8), uses (8), syntax (8), type (8), variants (8), integer (8), each (8), basic (8), repeat (8), wikipedia (7), page (7), php (7), org (7), article (7), via (7), section (7), what (7), bash (7), reference (7), simple (7), data (7), get (7), until (7), both (7), collection (7), middle (7), next (7), main (7), last (6), less (6), acm (6), science (6), machine (6), commands (6), construction (6), list (6), problem (6), conditions (6), found (6), out (6), provides (6), even (6), specified (6), reaches (6), requires (6), since (6), often (6), coroutine (6), have (6), been (6), functions (6), coroutines (6), values (6), like (6), state (6), times (6), block (6), including (6), clause (6), number (6), support (6), call (6), cases (6), supported (6), although (6), include (6), start (6), switch (6), terms (5), links (5), considered (5), 2019 (5), 978 (5), 2016 (5), how (5), between (5), eiffel (5), stack (5), operator (5), lists (5), dijkstra (5), std (5), exits (5), software (5), event (5), proposed (5), implemented (5), more (5), depending (5), processing (5), logic (5), must (5), excerpt (5), generators (5), special (5), sequence (5), however (5), object (5), catch (5), dosomething (5), unstructured (5), supports (5), these (5), true (5), provide (5), invariants (5), form (5), usually (5), displaystyle (5), another (5), keyword (5), actiononnomatch (5), actiononyandz (5), actiononx (5), actionona (5), somechar (5), printf (5), toggle (4), contents (4), search (4), commons (4), haskell (4), short (4), manual (4), harmful (4), top (4), doi (4), 2004 (4), compiler (4), isbn (4), overflow (4), error (4), looping (4), kosaraju (4), 2024 (4), redo (4), process (4), see (4), exitwhen (4), exceptions (4), variant (4), occurs (4), before (4), local (4), term (4), they (4), continuations (4), current (4), step (4), implements (4), being (4), create (4), file (4), whether (4), set (4), handler (4), someexception (4), standard (4), possible (4), iterate (4), over (4), added (4), labels (4), increment (4), builtin (4), per (4), arrays (4), begin (4), sublanguage (4), negative (4), shell (4), either (4), multilevel (4), continue (4), various (4), second (4), repeated (4), controlled (4), expressions (4), string (4), default (4), instruction (4), imperative (4), hide (4), move (4), sidebar (4), topic (3), view (3), about (3), additional (3), you (3), wikimedia (3), smalltalk (3), wikidata (3), wayback (3), index (3), related (3), external (3), 2014 (3), 1145 (3), design (3), diagram (3), history (3), donald (3), collections (3), net (3), 2010 (3), com (3), macro (3), 2025 (3), watt (3), 1973 (3), system (3), false (3), open (3), information (3), named (3), lang (3), perldoc (3), way (3), iterations (3), endless (3), new (3), algorithm (3), complexity (3), modeling (3), missing (3), target (3), endexit (3), searching (3), occur (3), here (3), instructions (3), written (3), intercal (3), others (3), same (3), order (3), depends (3), transfers (3), will (3), entire (3), specifies (3), later (3), components (3), class (3), always (3), rather (3), returns (3), containing (3), once (3), allows (3), immediately (3), processstuff (3), filestream (3), propagates (3), effect (3), caught (3), typical (3), integers (3), retry (3), range (3), through (3), because (3), visual (3), native (3), invariant (3), during (3), expression (3), omitted (3), reversing (3), read (3), char (3), sequencers (3), sequencer (3), commonly (3), depth (3), without (3), labeled (3), contains (3), style (3), solution (3), least (3), performed (3), duplicated (3), inside (3), unless (3), iterates (3), functional (3), multiway (3), matching (3), branches (3), foo (3), void (3), sequences (3), success (3), sequential (3), progresses (3), tools (3), add (2), legal (2), contact (2), privacy (2), policy (2), organization (2), september (2), hidden (2), categories (2), javascript (2), algol (2), link (2), template (2), description (2), 2009 (2), linguistic (2), wikibook (2), zahn (2), presented (2), natural (2), william (2), july (2), 2018 (2), datamation (2), don (2), know (2), come (2), lawrence (2), 1963 (2), s2cid (2), conway (2), melvin (2), vol (2), 2023 (2), anthony (2), nature (2), encyclopedia (2), scheme (2), difference (2), iterator (2), boost (2), for_each (2), comma (2), gnu (2), implementation (2), make (2), throw (2), dahl (2), press (2), 1972 (2), david (2), rao (2), analysis (2), programs (2), theory (2), computing (2), cited (2), theorem (2), notes (2), 540 (2), pep (2), 3136 (2), docs (2), control_expressions (2), documentation (2), them (2), personal (2), 278 (2), edsger (2), www (2), examples (2), endgame (2), reading (2), attack (2), properties (2), references (2), source (2), represents (2), tool (2), representation (2), two (2), dimensional (2), purpose (2), events (2), within (2), their (2), indicated (2), very (2), clear (2), situation (2), eventa (2), eventb (2), eventc (2), version (2), seen (2), joke (2), along (2), were (2), assembly (2), multiple (2), otherwise (2), needed (2), processor (2), resulting (2), argument (2), opposite (2), iterators (2), cooperative (2), known (2), back (2), caller (2), array (2), returning (2), time (2), would (2), ability (2), possibly (2), given (2), useful (2), runtime (2), filemode (2), logfile (2), txt (2), pattern (2), null (2), finally (2), divide (2), zero (2), result (2), mynumber (2), keywords (2), applescript (2), println (2), types (2), propagated (2), exceptional (2), starts (2), raised (2), proceeds (2), inner (2), handles (2), normal (2), handlers (2), flows (2), aspects (2), had (2), especially (2), subscriptrange (2), programmers (2), avoid (2), define (2), interest (2), check (2), those (2), dynamic (2), notable (2), odin (2), concept (2), procedures (2), specification (2), stl (2), functionality (2), containers (2), accomplished (2), counting (2), iterating (2), incrementing (2), apl (2), powershell (2), rust (2), correctness (2), cross (2), contain (2), implies (2), terminates (2), constructions (2), allow (2), idiomatic (2), script (2), single (2), traditional (2), bottom (2), polarity (2), adding (2), xxx2 (2), xxx1 (2), notion (2), defined (2), cannot (2), variables (2), furthermore (2), hierarchy (2), exists (2), together (2), currently (2), usual (2), alternative (2), implement (2), prime (2), beginning (2), results (2), explicitly (2), skipped (2), checking (2), sometimes (2), solutions (2), scala (2), asynchronous (2), somecollection (2), coll (2), somearray (2), enumeration (2), three (2), pre (2), family (2), variations (2), hardware (2), might (2), rounding (2), relatively (2), larger (2), recursive (2), gets (2), select (2), match (2), shows (2), echo (2), puts (2), writeln (2), messages (2), arithmetic (2), high (2), closely (2), follows (2), describes (2), blocks (2), identifies (2), position (2), confused (2), alters (2), appearance (2), upload (2), changes (2), subsection (2), log (2), account (2), donate (2), menu (2), mobile, cookie, statistics, developers, conduct, safety, contacts, disclaimers, text, available, under, apply, site, agree, registered, trademark, profit, foundation, inc, creative, attribution, sharealike, license, rendered, parsoid, edited, 2026, utc, matlab, octave, sharp, category, excerpts, webarchive, different, recursion, comparisons, https, title, control_flow, oldid, 1374573496, ibm, 704, contribution, media, symposium, paris, down, modell, howard, slater, april, 1978, 953411, 953418, sigplan, notices, innovation, lives, expectations, clarke, 408, 2022, digital, library, 10559786, 0001, 0782, issn, 366663, 366704, 396, communications, separable, transition, 1997, art, 3rd, addison, wesley, bibliography, 229, 201, 89683, fundamental, algorithms, ervin, tall, snarky, canadian, heck, async, await, work, ralston, 2000, pub, group, 2013, 56159, 248, kiselyov, oleg, january, ways, traverse, sandbox, sourceforge, chapter, sgi, meyer, bertrand, 1991, prentice, hall, 131, 129, exchange, could, prone, hoare, academic, findlay, john, wiley, sons, 221, 470, 85320, 215, concepts, proc, fifth, annual, syrup, 240, 252, sciences, december, kozen, dexter, 2008, böhm, jacopini, propositionally, lecture, 5133, 192, 70593, 1007, 70594, 9_11, 177, mathematics, guido, van, rossum, 3000, announcing, technology, comp, faq, question, 20b, advanced, scripting, guide, solve, 279, communication, wikiwikiweb, messy, dictionary, definition, dean, jenna, startup, w3schools, geeksforgeeks, roberts, 1995, sigcse, bulletin, 268, 272, reopening, debate, 301, 207630080, 356635, 356640, 261, surveys, release, prnewswire, present, black, hat, usa, november, 2015, dark, adobe, flash, bug, discovery, leads, mitigation, method, kuznetsov, volodymyr, nebelwelt, differences, cfi, cps, cpi, payer, mathias, poor, spaghetti, workflow, flowchart, mapping, drakon, measure, structural, cyclomatic, graphical, graph, business, technique, involves, particular, conceptually, specify, occurrence, name, relevant, carried, passes, just, separation, determining, applies, taken, actiona, actionb, actionc, discussed, modified, initially, cmfrm, elaborated, upon, clark, response, letter, eventually, obscure, computed, proposals, assigned, dont, complement, existing, esoteric, semantics, varies, invalid, deterministic, induce, citation, threaded, concurrent, parallel, major, global, interpreter, scan, points, tends, difficult, understand, indication, near, fact, study, causes, intended, serious, identified, continues, coined, 1958, applied, published, explanation, appeared, described, whose, pause, suspended, resumed, generalizing, well, suited, implementing, familiar, pipes, tasks, multitasking, subroutines, expressive, semicoroutines, weaker, yield, passing, specifying, comparison, behaviour, generates, building, started, few, behaves, looks, memory, yields, parameters, routine, computation, perspective, running, derived, refer, give, save, computational, created, accessed, encoding, mechanisms, environment, reifies, abstract, ensure, cleanup, released, close, rest, ensures, closed, display, dialog, partial, introduce, incorporates, placeholders, extract, shown, donextthing, unknown, const, demonstrates, matches, message, printed, modern, natively, generally, thrown, reverts, outward, outermost, scope, progressively, outer, normally, popping, handled, automatically, unfortunately, implementations, substantial, overhead, space, tried, decide, should, resume, zerodivide, endfile, intercepted, own, earliest, compilers, independence, included, 2003, numerical, issues, calls, module, ieee_exceptions, quotient, accumulator, favoring, styles, offer, cause, follow, predeclared, shortcuts, predates, generic, achieved, require, transfinite, why, jml, behavioral, interface, reserved, word, effected, across, interval, introduced, element, constructed, unary, users, simulated, instance, objects, gotos, specifically, init, count, dedicated, zig, swift, rebol, qb64, ocaml, maybe, kotlin, cobol, facilities, dialects, extensive, describing, conversional, interlisp, assertion, remain, correctly, satisfied, monitor, specific, successive, practical, initial, decrease, never, become, correct, guarantee, terminate, express, strlen, read_string, marginal, primarily, modify, statement_b, statement_a, statement_2, statement_1, shoehorning, into, status, separated, newlines, above, consequent, works, accepts, formally, bourne, forth, widely, thought, further, omitting, individual, replace, several, equivalent, keeping, unlike, functioning, atendoffile, write, his, textbook, tennent, explain, similarity, textually, enclosing, procedure, encompasses, carry, whereas, contemporary, escape, gives, rise, today, refined, proving, long, arbitrary, allowed, proved, strict, every, rewritten, introducing, theoretical, breaking, circles, levels, alternatives, variable, tested, broken, placing, termination, neither, nor, inclusion, feature, rejected, basis, worth, rare, legitimate, c29, did, numbers, isprime, set_of_numbers, exited, linked, occurred, stop, restarts, restart, cycle, skip, completion, criteria, continuing, subtlety, rewriting, recognized, 1967, wirth, suggesting, solving, 1990s, taught, dubbed, now, preparing, structures, arises, reasons, eliminate, minimize, duplication, having, duplicating, wrapping, determine, halting, endlessly, intervention, turning, off, power, pulling, plug, intentional, generalise, comprehensions, forall, alias, mystringcollection, tcl, mycollection, raku, eachelement, enumerate, items, int, evaluated, place, initialize, third, elsewhere, post, completely, reliably, floating, represented, imprecisely, due, constraints, factors, addition, accumulated, errors, mean, differ, quite, significantly, expected, yet, ends, smaller, processes, expressed, syntactic, tail, iterative, frequently, previous, met, hand, outside, infinitely, indefinite, definite, esac, provision, optimizations, limited, constant, extend, right, decode, sql, glob, lookup, tables, plusp, princ, conditionals, iffalse, iftrue, supplements, ternary, tests, positive, deemed, obsolete, deleted, restricted, mimics, boolean, provided, upper, lower, words, scientists, unconditionally, controlling, moves, bar, completes, calling, completing, printing, devised, organized, still, workin, organizing, curly, braces, delimit, bool, alphanumeric, appearing, followed, colon, defines, identifier, let, limit, inherent, none, typically, required, marking, lines, rules, limits, sequencing, selection, redirect, variety, techniques, shadow, stacks, pointer, verification, defend, against, attacks, vtable, buffer, protection, canaries, integrity, transfer, interrupted, signal, interrupt, unconditional, approach, conditionally, enables, branching, predication, counter, central, unit, encodes, focused, desired, prescribing, operations, though, declarative, paradigms, contexts, sequentially, located, executing, except, classified, context, its, redirected, free, wikibooks, projects, printable, download, export, legacy, parser, shortened, url, cite, permanent, actions, english, talk, tiếng, việt, اردو, українська, ไทย, தமிழ், svenska, српски, srpski, srpskohrvatski, српскохрватски, русский, português, polski, norsk, bokmål, nederlands, bahasa, melayu, 한국어, қазақша, 日本語, italiano, íslenska, hrvatski, עברית, français, فارسی, euskara, español, esperanto, deutsch, čeština, català, azərbaycanca, العربية, pages, recent, community, portal, learn, help, contribute, random, navigation, content,
Text of the page (random words):
provision for a default action if no match is found a switch statement can allow compiler optimizations such as lookup tables in dynamic languages the cases may not be limited to constant expressions and might extend to pattern matching as in the shell script example on the right where the implements the default case as a glob matching any string case logic can also be implemented in functional form as in sql s decode statement the following pascal code shows a relatively simple switch statement pascal uses the case keyword instead of switch case somechar of a actionona x actiononx y z actiononyandz else actiononnomatch end in ada case somechar is when a actionona when x actiononx when y z actiononyandz when others actiononnomatch end in c switch somechar case a actionona break case x actiononx break case y case z actiononyandz break default actiononnomatch in bash case somechar in a actionona x actiononx yz actiononyandz actiononnomatch esac in lisp case some char a action on a x action on x y z action on y and z else action on no match in fortran select case somechar case a actionona case x actiononx case y z actiononyandz case default actiononnomatch end select loops edit basic types of program loops main article loop statement in a loop a sequence of statements frequently called the loop body gets re executed at least in part after a conditional branch or jump to a previous step in the sequence the number of times a loop gets executed usually depends on runtime state for example the body is executed once for each item of a collection definite iteration until a condition is met indefinite iteration some loops on the other hand may repeat infinitely it is possible for a loop to be written as an infinite loop but for loop exit to be controlled by a test within the loop body that transfers control outside the loop early exit from a loop may be supported via a break statement 4 5 a loop inside the loop body of another loop is called a nested loop 6 7 8 in a functional programming language such as haskell and scheme both recursive and iterative processes are expressed with tail recursive procedures instead of looping constructs that are syntactic numeric edit main article for loop a relatively simple yet useful loop iterates over a range of numeric values a simple form starts at an integer value ends at a larger integer value and iterates for each integer value between often the increment can be any integer value even negative to loop from a larger to a smaller value example in basic for i 1 to n xxx next i example in pascal for i 1 to n do begin xxx end example in fortran do i 1 n xxx end do in many programming languages only integers can be used at all or reliably as a floating point number is represented imprecisely due to hardware constraints the following loop might iterate 9 or 10 times depending on various factors such as rounding error hardware compiler furthermore if the increment of x occurs by repeated addition accumulated rounding errors may mean that the value of x in each iteration can differ quite significantly from the commonly expected sequence of 0 1 0 2 0 3 1 0 for x 0 1 step 0 1 to 1 0 do condition controlled edit main articles while loop and do while loop some loop constructs iterate until a condition is true some variations test the condition at the start of the loop others test at the end if the test is at the start the body may be skipped completely at the end the body is always executed at least once example in visual basic do while test xxx loop example in pascal repeat xxx until test example in c family of pre test while test xxx example in c family of post test do xxx while test although using the for keyword the three part c style loop is a condition based construct not a numeric based one the second part the condition is evaluated before each loop so the loop is pre test the first part is a place to initialize state and the third part is for incrementing for the next iteration but both aspects can be performed elsewhere the following c code implements the logic of a numeric loop that iterates for i from 0 to n 1 for int i 0 i n i xxx enumeration edit main article foreach some loop constructs enumerate the items of a collection iterating for each item example in smalltalk somecollection do eachelement xxx example in pascal for item in collection do begin xxx end example in raku foreach item mycollection xxx example in tcl foreach somearray xxx example in php foreach somearray as k v xxx example in java collection string coll for string s coll example in c foreach string s in mystringcollection xxx example in powershell where foreach is an alias of foreach object somecollection foreach _ example in fortran forall index first last step scala has for expressions which generalise collection controlled loops and also support other uses such as asynchronous programming haskell has do expressions and comprehensions which together provide similar function to for expressions in scala infinite edit this section is an excerpt from infinite loop edit loop constructs do while loop while loop for loop foreach loop infinite loop control flow v t e in computer programming an infinite loop or endless loop 9 10 is a sequence of instructions that as written will continue endlessly unless an external intervention occurs such as turning off power via a switch or pulling a plug it may be intentional there is no general algorithm to determine whether a computer program contains an infinite loop or not this is the halting problem loop and a half problem edit common loop structures sometimes result in duplicated code either repeated statements or repeated conditions this arises for various reasons and has various proposed solutions to eliminate or minimize code duplication 11 other than the traditional unstructured solution of a goto statement 12 general structured solutions include having a conditional if statement inside the loop possibly duplicating the condition but not the statements or wrapping repeated logic in a function so there is a duplicated function call but the statements are not duplicated 11 a common case is where the start of the loop is always executed but the end may be skipped on the last iteration 12 this was dubbed by dijkstra a loop which is performed n and a half times 13 and is now called the loop and a half problem 5 common cases include reading data in the first part checking for end of data and then processing the data in the second part or processing checking for end and then preparing for the next iteration 12 5 in these cases the first part of the loop is executed n displaystyle n times but the second part is only executed n 1 displaystyle n 1 times this problem has been recognized at least since 1967 by knuth with wirth suggesting solving it via early loop exit 14 since the 1990s this has been the most commonly taught solution using a break statement as in 5 loop statements if condition break statements repeat a subtlety of this solution is that the condition is the opposite of a usual while condition rewriting while condition repeat with an exit in the middle requires reversing the condition loop if not condition exit repeat the loop with test in the middle control structure explicitly supports the loop an a half use case without reversing the condition 14 unstructured edit a loop construct provides for structured completion criteria that either results in another iteration or continuing execution after the loop statement but various unstructured control flow constructs are supported by many languages early next iteration some languages provide a construct that jumps control to the beginning of the loop body for the next iteration for example continue most common skip 15 cycle fortran or next perl and ruby redo iteration some languages like perl 16 and ruby 17 have a redo statement that jumps to the start of the body for the same iteration restart ruby has a retry statement that restarts the entire loop from the first iteration 18 early exit edit early exit jumps control to after the loop body 19 5 for example when searching a list can stop looping when the item is found some programming languages provide a statement such as break most languages exit visual basic or last perl in the following ada code the loop exits when x is 0 loop get x if x 0 then exit end if dosomething x end loop a more idiomatic style uses exit when loop get x exit when x 0 dosomething x end loop python supports conditional execution of code depending on whether a loop was exited early with a break statement or not by using an else clause with the loop in the following python code the else clause is linked to the for statement and not the inner if statement both python s for and while loops support such an else clause which is executed only if early exit of the loop has not occurred for n in set_of_numbers if isprime n print set contains a prime number break else print set did not contain any prime numbers multi level breaks edit some languages support breaking out of nested loops in theory circles these are called multi level breaks one common use example is searching a multi dimensional table this can be done either via multilevel breaks break out of n displaystyle n levels as in bash 20 and php 21 or via labeled breaks break out and continue at given label as in ada go java rust and perl 22 alternatives to multilevel breaks include single breaks together with a state variable which is tested to break out another level exceptions which are caught at the level being broken out to placing the nested loops in a function and using return to effect termination of the entire nested loop or using a label and a goto statement neither c nor c currently have multilevel break or named loops and the usual alternative is to use a goto to implement a labeled break 23 however the inclusion of this feature has been proposed 24 and was added to c29 25 following the java syntax python does not have a multilevel break or continue this was proposed in pep 3136 and rejected on the basis that the added complexity was not worth the rare legitimate use 26 the notion of multi level breaks is of some interest in theoretical computer science because it gives rise to what is today called the kosaraju hierarchy 27 in 1973 s rao kosaraju refined the structured program theorem by proving that it is possible to avoid adding additional variables in structured programming as long as arbitrary depth multi level breaks from loops are allowed 28 furthermore kosaraju proved that a strict hierarchy of programs exists for every integer n displaystyle n there exists a program containing a multi level break of depth n displaystyle n that cannot be rewritten as a program with multi level breaks of depth less than n without introducing added variables 27 in his 2004 textbook david watt uses tennent s notion of sequencer to explain the similarity between multi level breaks and return statements watt notes that a class of sequencers known as escape sequencers defined as sequencer that terminates execution of a textually enclosing command or procedure encompasses both breaks from loops including multi level breaks and return statements as commonly implemented however return sequencers may also carry a return value whereas the break sequencer as implemented in contemporary languages usually cannot 29 middle test edit the following structure was proposed by dahl in 1972 30 loop loop xxx1 read char while test while not atendoffile xxx2 write char repeat repeat the construction here can be thought of as a do loop with the while check in the middle which allows clear loop and a half logic further by omitting individual components this single construction can replace several constructions in most programming languages if xxx1 is omitted we get a loop with the test at the top a traditional while loop if xxx2 is omitted we get a loop with the test at the bottom equivalent to a do while loop in many languages if while is omitted we get an infinite loop this construction also allows keeping the same polarity of the condition even when in the middle unlike early exit which requires reversing the polarity adding a not 14 functioning as until instead of while this structure is not widely supported with most languages instead using if break for conditional early exit this is supported by some languages such as forth where the syntax is begin while repeat 31 and the shell script languages bourne shell sh and bash where the syntax is while do done or until do done as 32 33 while statement 1 statement 2 condition do statement a statement b done the shell syntax works because the while or until loop accepts a list of commands as a condition 34 formally while test commands do consequent commands done the value exit status of the list of test commands is the value of the last command and these can be separated by newlines resulting in the idiomatic form above similar constructions are possible in c and c with the comma operator and other languages with similar constructs which allow shoehorning a list of statements into the while condition while statement_1 statement_2 condition statement_a statement_b while legal this is marginal and it is primarily used if at all only for short modify then test cases as in 35 while read_string s strlen s 0 loop variants and invariants edit loop variants and loop invariants are used to express correctness of loops 36 in practical terms a loop variant is an integer expression which has an initial non negative value the variant s value must decrease during each loop iteration but must never become negative during the correct execution of the loop loop variants are used to guarantee that loops will terminate a loop invariant is an assertion which must be true before the first loop iteration and remain true after each iteration this implies that when a loop terminates correctly both the exit condition and the loop invariant are satisfied loop invariants are used to monitor specific properties of a loop during successive iterations some programming languages such as eiffel contain native support for loop variants and invariants in other cases support is an add on such as the java modeling language s specification for loop statements in java loop sublanguage edit some lisp dialects provide an extensive sublanguage for describing loops an early example can be found in conversional lisp of interlisp common lisp 37 provides a loop macro which implements such a sublanguage loop system cross reference table edit programming language conditional loop early exit loop continuation redo retry correctness facilities begin middle end numeric collection general infinite 1 variant invariant ada yes yes yes yes arrays no yes deep nested no apl yes no yes yes yes yes yes deep nested 3 yes no no c yes no yes no 2 no yes no deep nested 3 deep nested 3 no no no no c yes no yes no 2 yes 9 yes no deep nested 3 deep nested 3 no no no no c yes no yes no 2 yes ...
|