Knowledge

Short-circuit evaluation

Source 📝

32: 2613:
Problems with unperformed side effect statements can be easily solved with proper programming style, i.e., not using side effects in boolean statements, as using values with side effects in evaluations tends to generally make the code opaque and error-prone.
380:
in the case A ∧ C , the second expression requires B to be defined, the first one does not. Because the conditional connectives thus complicate the formal reasoning about programs, they are better avoided.
468:, where short-circuit operators may return the last evaluated subexpression. This is called "last value" in the table below. For a strictly-typed language, the expression is simplified to 217:
in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the
3075: 2547:
Despite these benefits, minimal evaluation may cause problems for programmers who do not realize (or forget) it is happening. For example, in the code
649:
As you look at the table below, keep in mind that bitwise operators often do not behave exactly like logical operators, even if both arguments are of
518:
in many languages, this is not a universal property of short-circuit evaluation. An example of the two operators taking the same precedence and being
2070: 2154:
languages that supported CASE statements did so by using the conditional evaluation system, rather than as jump tables limited to fixed labels.
181: 2334:
Both are illustrated in the following C snippet where minimal evaluation prevents both null pointer dereference and excess memory fetches:
2858: 2834: 96: 641:. A result is that non-short-circuiting operators can be defined out of short-circuit logic to have the same sequence of evaluation. 68: 49: 2822: 2634:. Some compilers can detect such cases and emit faster code, but programming language semantics may constrain such optimizations. 2630:(CPUs), and dramatically reduce performance. A notable example is highly optimized ray with axis aligned box intersection code in 2964: 75: 3004: 82: 2326:
It permits a construct where the first expression guarantees a condition without which the second expression may cause a
2973: 2775: 206: 174: 115: 64: 3065: 3060: 1203: 986: 310: 53: 1894: 1666: 1520: 1468: 1395: 1359: 1143: 1115: 2689: 3070: 1327: 1303: 1243: 167: 3009: 2957: 2882: 2638: 2607: 2319:
If the first sub-expression checks whether an expensive computation is needed and the check evaluates to
1730: 1694: 1387: 1231: 282:(XOR), it is impossible to short-circuit, because both operands are always needed to determine a result. 269: 249: 2610:, have two operators, one that employs minimal evaluation and one that does not, to avoid this problem. 2929:"Java: What are the cases in which it is better to use unconditional AND (& instead of &&)" 1391: 1038: 805: 758: 265: 276:), both short-circuit and standard Boolean operators are available. For some Boolean operations, like 89: 2903: 2642: 1199: 408: 2749: 2172: 1239: 1071: 890: 298: 457:
The generalized definition above accommodates loosely typed languages that have more than the two
2989: 2984: 2627: 42: 2950: 2458:, a number of coding idioms rely on it as a succinct conditional construct. Examples include: 2631: 2455: 2057:
Fortran operators are neither short-circuit nor eager: the language specification allows the
2738: 2727: 3029: 2020: 214: 2761: 2454:
Since minimal evaluation is part of an operator's semantic definition and not an optional
638: 8: 2677: 511: 294: 131: 3034: 3024: 2994: 2708: 2673: 2654: 385: 340:" for short — are ... less innocent than they might seem at first sight. For instance, 261: 210: 145: 20: 2623: 2085: 1862: 866: 397:
In any programming language that implements short-circuit evaluation, the expression
286: 273: 150: 1998:
The bitwise operators behave like boolean operators when both arguments are of type
1919: 718: 519: 2606:
will not execute, which could cause problems. Some programming languages, such as
637:
Short-circuit logic, with or without side-effects, have been formalized based on
290: 245: 140: 2048:. Expressions in static initializers or manifest constants use eager evaluation. 3039: 2799: 2327: 306: 2231:// ensures that calculating num/denom never results in divide-by-zero error 3054: 2999: 2542: 2707:
Bergstra, Jan A.; Ponse, A.; Staudt, D.J.C. (2010). "Short-circuit logic".
1890: 278: 2501: 2441:// 1) no unneeded isalpha() execution with p == NULL, 2) no SEGFAULT risk 2166: 2123: 2089: 1833: 1786: 1616: 894: 523: 458: 305:), where side effects are important, short-circuit operators introduce a 644: 2928: 2617: 1641: 1271: 328:
The use of short-circuit operators has been criticized as problematic:
529:
The following simple left-to-right evaluator enforces a precedence of
2676:"On a somewhat disappointing correspondence", EWD1009-0, 25 May 1987 2594:
is supposed to perform some required operation regardless of whether
1758: 31: 3014: 2142:. The entries in the table show how it works for Beckhoff TwinCATÂŽ. 2093: 2058: 1444: 786: 314: 2713: 2105:
Smalltalk uses short-circuit semantics as long as the argument to
2323:, one can eliminate expensive computation in the second argument. 2134:
use short-circuit evaluation and it doesn't define the operators
1171: 257: 2942: 664:
In JavaScript, each of the following 3 expressions evaluates to
2637:
An example of a compiler unable to optimize for such a case is
1808: 1235: 2728:
ISO/IEC 9899 standard, sections 6.2.5, 6.3.1.2, 6.5 and 7.16.
2151: 1492: 1419: 1207: 946: 309:: they completely evaluate the first argument, including any 302: 2092:
default to short circuit evaluation. This may be changed by
2461: 1548: 733: 253: 2904:"Referential Transparency, Definiteness and Unfoldability" 2543:
Untested second condition leads to unperformed side effect
2315:. This feature permits two useful programming constructs. 2303:
In this example, short-circuit evaluation guarantees that
1584: 842: 686:
In PHP, each of the following 3 expressions evaluates to
289:
rather than simple arithmetic operators, as they are not
2598:
is executed, such as allocating system resources, and
2167:
Avoiding undesired side effects of the second argument
313:, before (optionally) processing the second argument. 645:
Support in common programming and scripting languages
2618:
Reduced efficiency due to constraining optimizations
2040:
This only applies to runtime-evaluated expressions,
2706: 56:. Unsourced material may be challenged and removed. 3076:Implementation of functional programming languages 2449: 3052: 2073:allows, but does not require, short-circuiting. 2958: 175: 2481:# Abort execution if some_condition is false 2096:options but does not seem to be used widely. 693:(true & true) === (true && true) 671:(true & true) === (true && true) 2496:# Abort execution if some_condition is true 1989:ABAP and APL have no distinct boolean type. 732:Advanced Business Application Programming ( 2965: 2951: 2381:// SEGFAULT highly possible with p == NULL 1985: 1983: 182: 168: 2926: 2712: 2099: 2081: 2079: 116:Learn how and when to remove this message 2823:ETSI ES 201 873-1 V4.10.1, section 7.1.4 2776:"operators - Documentation for Ruby 3.3" 2064: 1992: 325:short-circuit operators and procedures. 285:Short-circuit operators are, in effect, 2859:"Beckhoff Information System - English" 2835:"Beckhoff Information System - English" 2622:Short-circuiting can lead to errors in 2116: 2051: 1980: 710:Boolean operators in various languages 3053: 2076: 2061:to select the method for optimization. 2946: 2739:ISO/IEC 9899 standard, section 6.5.13 2525:"some_module not installed" 2145: 229:; and when the first argument of the 2537: 676:(false | false) === (false || false) 54:adding citations to reliable sources 25: 498:respectively for the boolean case. 13: 2071:ISO/IEC 10206:1990 Extended Pascal 2031:are eager and can return any type. 2013: 14: 3087: 2972: 2927:Wasserman, Louis (11 July 2012). 2516:"some_module installed" 2307:is never called. This is because 2034: 2342:is_first_char_valid_alpha_unsafe 2239:Consider the following example: 703:(1 & 2) === (1 && 2) 681:(1 & 2) === (1 && 2) 632: 30: 2920: 2896: 2875: 2851: 2827: 2816: 2792: 2768: 2754: 2450:Idiomatic conditional construct 332:The conditional connectives — " 41:needs additional citations for 2743: 2732: 2721: 2700: 2682: 2667: 244:In programming languages with 16:Programming language construct 1: 2660: 2161: 1895:Visual Basic for Applications 501: 392: 2883:"What does || mean in bash?" 2762:"OCaml - the OCaml language" 237:, the overall value must be 225:, the overall value must be 7: 2648: 2126:doesn't actually define if 791:and, &, ∧ ; or, ∨ 209:) is the semantics of some 10: 3092: 1039:ColdFusion Markup Language 264:short-circuit. In others ( 65:"Short-circuit evaluation" 18: 2980: 2602:evaluates as false, then 2530:This idiom presumes that 2390:is_first_char_valid_alpha 538: 534: 530: 515: 507: 344:does not distribute over 2690:"Shell Command Language" 2628:central processing units 2549: 2506: 2466: 2336: 2241: 2177: 2002:or take only the values 526:'s command-list syntax. 454:is only evaluated once. 195:Short-circuit evaluation 156:Short-circuit evaluation 19:Not to be confused with 2985:Artificial intelligence 2750:ISO/IEC IS 14882 draft. 2643:Hotspot virtual machine 2171:Usual example, using a 724:Short-circuit operators 3066:Conditional constructs 3061:Compiler optimizations 409:conditional expression 390: 233:function evaluates to 221:function evaluates to 2508:modprobe-qsome_module 425:, and the expression 407:is equivalent to the 330: 215:programming languages 132:Evaluation strategies 3030:McCarthy 91 function 2863:infosys.beckhoff.com 2839:infosys.beckhoff.com 698:(0 | 0) === (0 || 0) 593:= False 547:short-circuit-eval ( 50:improve this article 3071:Evaluation strategy 3020:McCarthy evaluation 2885:. stackexchange.com 1832:Beckhoff TwinCATÂŽ ( 1644:Scripting Language 1106:), opnd-dependent ( 1025:), opnd-dependent ( 977:), opnd-dependent ( 937:), opnd-dependent ( 796:(both user defined) 711: 639:Hoare's conditional 607:= True 589:= "AND" && 522:with each other is 295:imperative language 203:McCarthy evaluation 3035:Situation calculus 3025:McCarthy Formalism 3005:Garbage collection 2995:Dartmouth workshop 2780:docs.ruby-lang.org 2694:pubs.opengroup.org 2674:Edsger W. Dijkstra 2109:is a block (e.g., 1636:Last value (exit) 709: 603:= "OR" && 562: := True 450:. In either case, 386:Edsger W. Dijkstra 287:control structures 199:minimal evaluation 146:Partial evaluation 21:Short-circuit test 3048: 3047: 2804:doc.rust-lang.org 2800:"std::ops - Rust" 2645:(VM) as of 2012. 2624:branch prediction 2538:Possible problems 1976: 1975: 1863:Visual Basic .NET 657:or Boolean type. 435:is equivalent to 262:Boolean operators 211:Boolean operators 192: 191: 151:Remote evaluation 126: 125: 118: 100: 3083: 2967: 2960: 2953: 2944: 2943: 2937: 2936: 2924: 2918: 2917: 2915: 2914: 2908: 2900: 2894: 2893: 2891: 2890: 2879: 2873: 2872: 2870: 2869: 2855: 2849: 2848: 2846: 2845: 2831: 2825: 2820: 2814: 2813: 2811: 2810: 2796: 2790: 2789: 2787: 2786: 2772: 2766: 2765: 2758: 2752: 2747: 2741: 2736: 2730: 2725: 2719: 2718: 2716: 2704: 2698: 2697: 2686: 2680: 2671: 2605: 2601: 2597: 2593: 2586: 2583: 2580: 2577: 2574: 2571: 2568: 2565: 2562: 2559: 2556: 2553: 2533: 2526: 2523: 2520: 2517: 2514: 2511: 2497: 2494: 2491: 2488: 2485: 2482: 2479: 2476: 2473: 2470: 2445: 2442: 2439: 2436: 2433: 2430: 2427: 2424: 2421: 2418: 2415: 2412: 2409: 2406: 2403: 2400: 2397: 2394: 2391: 2388: 2385: 2382: 2379: 2376: 2373: 2370: 2367: 2364: 2361: 2358: 2355: 2352: 2349: 2346: 2343: 2340: 2310: 2306: 2299: 2296: 2293: 2290: 2287: 2284: 2281: 2278: 2275: 2272: 2269: 2266: 2263: 2260: 2257: 2254: 2251: 2248: 2245: 2235: 2232: 2229: 2226: 2223: 2220: 2217: 2214: 2211: 2208: 2205: 2202: 2199: 2196: 2193: 2190: 2187: 2184: 2181: 2155: 2149: 2143: 2141: 2137: 2133: 2129: 2120: 2114: 2112: 2108: 2103: 2097: 2083: 2074: 2068: 2062: 2055: 2049: 2047: 2043: 2038: 2032: 2030: 2026: 2023:, the operators 2017: 2011: 2009: 2005: 2001: 1996: 1990: 1987: 1964: 1960: 1947: 1943: 1939: 1935: 1930: 1926: 1920:Wolfram Language 1911: 1906: 1902: 1882: 1878: 1873: 1869: 1854: 1850: 1845: 1841: 1824: 1820: 1800: 1796: 1778: 1774: 1769: 1765: 1750: 1746: 1741: 1737: 1722: 1718: 1714: 1710: 1705: 1701: 1686: 1682: 1677: 1673: 1658: 1654: 1633: 1629: 1608: 1604: 1600: 1596: 1576: 1572: 1568: 1564: 1559: 1555: 1540: 1536: 1531: 1527: 1512: 1508: 1503: 1499: 1484: 1480: 1460: 1456: 1431: 1427: 1411: 1407: 1379: 1375: 1370: 1366: 1351: 1347: 1343: 1339: 1319: 1315: 1295: 1291: 1287: 1283: 1263: 1259: 1254: 1250: 1223: 1219: 1191: 1187: 1182: 1178: 1163: 1159: 1154: 1150: 1135: 1131: 1126: 1122: 1109: 1105: 1101: 1095: 1091: 1087: 1082: 1078: 1063: 1059: 1055: 1051: 1032: 1028: 1024: 1020: 1014: 1010: 1006: 1002: 997: 993: 980: 976: 972: 966: 962: 958: 940: 936: 932: 928: 924: 918: 914: 910: 905: 901: 882: 878: 858: 854: 834: 830: 824: 820: 816: 812: 778: 774: 769: 765: 750: 746: 712: 708: 704: 699: 694: 689: 682: 677: 672: 667: 656: 652: 540: 536: 532: 520:left-associative 517: 509: 497: 482: 467: 463: 449: 434: 424: 406: 388: 240: 236: 232: 228: 224: 220: 184: 177: 170: 128: 127: 121: 114: 110: 107: 101: 99: 58: 34: 26: 3091: 3090: 3086: 3085: 3084: 3082: 3081: 3080: 3051: 3050: 3049: 3044: 2990:Circumscription 2976: 2971: 2941: 2940: 2925: 2921: 2912: 2910: 2906: 2902: 2901: 2897: 2888: 2886: 2881: 2880: 2876: 2867: 2865: 2857: 2856: 2852: 2843: 2841: 2833: 2832: 2828: 2821: 2817: 2808: 2806: 2798: 2797: 2793: 2784: 2782: 2774: 2773: 2769: 2760: 2759: 2755: 2748: 2744: 2737: 2733: 2726: 2722: 2705: 2701: 2688: 2687: 2683: 2672: 2668: 2663: 2655:Don't-care term 2651: 2620: 2603: 2599: 2595: 2591: 2588: 2587: 2584: 2581: 2578: 2575: 2572: 2569: 2566: 2563: 2560: 2557: 2554: 2551: 2545: 2540: 2531: 2528: 2527: 2524: 2521: 2518: 2515: 2512: 2509: 2499: 2498: 2495: 2492: 2489: 2486: 2483: 2480: 2477: 2474: 2471: 2468: 2452: 2447: 2446: 2443: 2440: 2437: 2434: 2431: 2428: 2425: 2422: 2419: 2416: 2413: 2410: 2407: 2404: 2401: 2398: 2395: 2392: 2389: 2386: 2383: 2380: 2377: 2374: 2371: 2368: 2365: 2362: 2359: 2356: 2353: 2350: 2347: 2344: 2341: 2338: 2308: 2304: 2301: 2300: 2297: 2294: 2291: 2288: 2285: 2282: 2279: 2276: 2273: 2270: 2267: 2264: 2261: 2258: 2255: 2252: 2249: 2246: 2243: 2237: 2236: 2233: 2230: 2227: 2224: 2221: 2218: 2215: 2212: 2209: 2206: 2203: 2200: 2197: 2194: 2191: 2188: 2185: 2182: 2179: 2169: 2164: 2159: 2158: 2150: 2146: 2139: 2135: 2131: 2127: 2121: 2117: 2110: 2106: 2104: 2100: 2084: 2077: 2069: 2065: 2056: 2052: 2045: 2041: 2039: 2035: 2028: 2024: 2018: 2014: 2007: 2003: 1999: 1997: 1993: 1988: 1981: 1962: 1958: 1945: 1941: 1937: 1933: 1928: 1924: 1909: 1904: 1900: 1880: 1876: 1871: 1867: 1852: 1848: 1843: 1839: 1822: 1818: 1798: 1794: 1776: 1772: 1767: 1763: 1748: 1744: 1739: 1735: 1720: 1716: 1712: 1708: 1703: 1699: 1684: 1680: 1675: 1671: 1656: 1652: 1631: 1627: 1619:(command list) 1606: 1602: 1598: 1594: 1574: 1570: 1566: 1562: 1557: 1553: 1538: 1534: 1529: 1525: 1510: 1506: 1501: 1497: 1482: 1478: 1458: 1454: 1429: 1425: 1409: 1405: 1377: 1373: 1368: 1364: 1349: 1345: 1341: 1337: 1317: 1313: 1293: 1289: 1285: 1281: 1261: 1257: 1252: 1248: 1221: 1217: 1189: 1185: 1180: 1176: 1161: 1157: 1152: 1148: 1133: 1129: 1124: 1120: 1107: 1103: 1099: 1093: 1089: 1085: 1080: 1076: 1061: 1057: 1053: 1049: 1030: 1026: 1022: 1018: 1012: 1008: 1004: 1000: 995: 991: 978: 974: 970: 964: 960: 956: 938: 934: 930: 926: 922: 916: 912: 908: 903: 899: 880: 876: 856: 852: 832: 828: 822: 818: 814: 810: 776: 772: 767: 763: 748: 744: 702: 701: 697: 696: 692: 691: 687: 680: 679: 675: 674: 670: 669: 665: 654: 650: 647: 635: 630: 504: 484: 469: 465: 461: 436: 426: 411: 398: 395: 389: 384: 297:terms (notably 246:lazy evaluation 238: 234: 230: 226: 222: 218: 188: 141:Lazy evaluation 122: 111: 105: 102: 59: 57: 47: 35: 24: 17: 12: 11: 5: 3089: 3079: 3078: 3073: 3068: 3063: 3046: 3045: 3043: 3042: 3040:Space fountain 3037: 3032: 3027: 3022: 3017: 3012: 3007: 3002: 2997: 2992: 2987: 2981: 2978: 2977: 2970: 2969: 2962: 2955: 2947: 2939: 2938: 2933:Stack Overflow 2919: 2895: 2874: 2850: 2826: 2815: 2791: 2767: 2753: 2742: 2731: 2720: 2699: 2681: 2665: 2664: 2662: 2659: 2658: 2657: 2650: 2647: 2619: 2616: 2596:do_something() 2550: 2544: 2541: 2539: 2536: 2507: 2484:some_condition 2469:some_condition 2467: 2451: 2448: 2337: 2332: 2331: 2328:run-time error 2324: 2242: 2178: 2168: 2165: 2163: 2160: 2157: 2156: 2144: 2115: 2098: 2075: 2063: 2050: 2033: 2012: 1991: 1978: 1977: 1974: 1973: 1970: 1965: 1956: 1952: 1951: 1948: 1931: 1922: 1916: 1915: 1912: 1907: 1898: 1887: 1886: 1883: 1874: 1865: 1859: 1858: 1855: 1846: 1837: 1829: 1828: 1825: 1816: 1811: 1805: 1804: 1801: 1792: 1789: 1783: 1782: 1779: 1770: 1761: 1755: 1754: 1751: 1742: 1733: 1727: 1726: 1723: 1706: 1697: 1691: 1690: 1687: 1678: 1669: 1663: 1662: 1659: 1650: 1645: 1638: 1637: 1634: 1625: 1620: 1613: 1612: 1609: 1592: 1587: 1581: 1580: 1577: 1560: 1551: 1545: 1544: 1541: 1532: 1523: 1517: 1516: 1513: 1504: 1495: 1489: 1488: 1485: 1476: 1471: 1465: 1464: 1461: 1452: 1447: 1441: 1440: 1437: 1432: 1423: 1416: 1415: 1412: 1403: 1398: 1384: 1383: 1380: 1371: 1362: 1356: 1355: 1352: 1335: 1330: 1324: 1323: 1320: 1311: 1306: 1300: 1299: 1296: 1279: 1274: 1268: 1267: 1264: 1255: 1246: 1228: 1227: 1224: 1215: 1210: 1196: 1195: 1192: 1183: 1174: 1168: 1167: 1164: 1155: 1146: 1140: 1139: 1136: 1127: 1118: 1112: 1111: 1096: 1083: 1074: 1068: 1067: 1064: 1047: 1042: 1035: 1034: 1015: 998: 989: 983: 982: 967: 954: 949: 943: 942: 919: 906: 897: 887: 886: 883: 874: 869: 863: 862: 859: 850: 845: 839: 838: 835: 826: 808: 802: 801: 798: 792: 789: 783: 782: 779: 770: 761: 755: 754: 751: 742: 737: 729: 728: 725: 722: 716: 707: 706: 684: 646: 643: 634: 631: 543: 503: 500: 394: 391: 382: 378: 377: 307:sequence point 190: 189: 187: 186: 179: 172: 164: 161: 160: 159: 158: 153: 148: 143: 135: 134: 124: 123: 38: 36: 29: 15: 9: 6: 4: 3: 2: 3088: 3077: 3074: 3072: 3069: 3067: 3064: 3062: 3059: 3058: 3056: 3041: 3038: 3036: 3033: 3031: 3028: 3026: 3023: 3021: 3018: 3016: 3013: 3011: 3008: 3006: 3003: 3001: 3000:Frame problem 2998: 2996: 2993: 2991: 2988: 2986: 2983: 2982: 2979: 2975: 2974:John McCarthy 2968: 2963: 2961: 2956: 2954: 2949: 2948: 2945: 2934: 2930: 2923: 2905: 2899: 2884: 2878: 2864: 2860: 2854: 2840: 2836: 2830: 2824: 2819: 2805: 2801: 2795: 2781: 2777: 2771: 2763: 2757: 2751: 2746: 2740: 2735: 2729: 2724: 2715: 2710: 2703: 2695: 2691: 2685: 2679: 2675: 2670: 2666: 2656: 2653: 2652: 2646: 2644: 2640: 2635: 2633: 2629: 2625: 2615: 2611: 2609: 2548: 2535: 2534:cannot fail. 2505: 2503: 2465: 2463: 2459: 2457: 2335: 2329: 2325: 2322: 2318: 2317: 2316: 2314: 2311:evaluates to 2240: 2176: 2174: 2153: 2148: 2125: 2119: 2102: 2095: 2091: 2087: 2082: 2080: 2072: 2067: 2060: 2054: 2046:static assert 2037: 2022: 2016: 1995: 1986: 1984: 1979: 1971: 1969: 1966: 1957: 1954: 1953: 1949: 1932: 1923: 1921: 1918: 1917: 1913: 1908: 1899: 1896: 1892: 1889: 1888: 1884: 1875: 1866: 1864: 1861: 1860: 1856: 1847: 1838: 1835: 1831: 1830: 1826: 1817: 1815: 1812: 1810: 1807: 1806: 1802: 1793: 1790: 1788: 1785: 1784: 1780: 1771: 1762: 1760: 1757: 1756: 1752: 1743: 1734: 1732: 1729: 1728: 1724: 1707: 1698: 1696: 1693: 1692: 1688: 1679: 1670: 1668: 1665: 1664: 1660: 1651: 1649: 1646: 1643: 1640: 1639: 1635: 1626: 1624: 1621: 1618: 1615: 1614: 1610: 1593: 1591: 1588: 1586: 1583: 1582: 1578: 1561: 1552: 1550: 1547: 1546: 1542: 1533: 1524: 1522: 1519: 1518: 1514: 1505: 1496: 1494: 1491: 1490: 1486: 1477: 1475: 1472: 1470: 1467: 1466: 1462: 1453: 1451: 1448: 1446: 1443: 1442: 1438: 1436: 1433: 1424: 1421: 1418: 1417: 1413: 1404: 1402: 1399: 1397: 1393: 1389: 1386: 1385: 1381: 1372: 1363: 1361: 1358: 1357: 1353: 1336: 1334: 1331: 1329: 1326: 1325: 1321: 1312: 1310: 1307: 1305: 1302: 1301: 1297: 1280: 1278: 1275: 1273: 1270: 1269: 1265: 1256: 1247: 1245: 1241: 1237: 1233: 1230: 1229: 1225: 1216: 1214: 1211: 1209: 1205: 1201: 1198: 1197: 1193: 1184: 1175: 1173: 1170: 1169: 1165: 1156: 1147: 1145: 1142: 1141: 1137: 1128: 1119: 1117: 1114: 1113: 1097: 1084: 1075: 1073: 1070: 1069: 1065: 1048: 1046: 1043: 1040: 1037: 1036: 1016: 999: 990: 988: 985: 984: 968: 955: 953: 950: 948: 945: 944: 920: 907: 898: 896: 892: 889: 888: 884: 875: 873: 870: 868: 865: 864: 860: 851: 849: 846: 844: 841: 840: 836: 827: 809: 807: 804: 803: 799: 797: 793: 790: 788: 785: 784: 780: 771: 762: 760: 757: 756: 752: 743: 741: 738: 735: 731: 730: 726: 723: 720: 717: 714: 713: 685: 663: 662: 661: 658: 642: 640: 633:Formalization 629: 626: 623: 619: 616: 613: 610: 606: 602: 599: 596: 592: 588: 585: 581: 577: 573: 569: 565: 561: 558: 554: 550: 546: 542: 527: 525: 521: 513: 499: 496: 492: 488: 481: 477: 473: 460: 455: 453: 448: 444: 440: 433: 429: 423: 419: 415: 410: 405: 401: 387: 381: 375: 371: 367: 363: 359: 355: 351: 350: 349: 347: 343: 339: 335: 329: 326: 324: 320: 316: 312: 308: 304: 300: 296: 292: 288: 283: 281: 280: 275: 271: 267: 263: 260:), the usual 259: 255: 251: 247: 242: 216: 212: 208: 207:John McCarthy 204: 200: 196: 185: 180: 178: 173: 171: 166: 165: 163: 162: 157: 154: 152: 149: 147: 144: 142: 139: 138: 137: 136: 133: 130: 129: 120: 117: 109: 98: 95: 91: 88: 84: 81: 77: 74: 70: 67: â€“  66: 62: 61:Find sources: 55: 51: 45: 44: 39:This article 37: 33: 28: 27: 22: 3019: 2932: 2922: 2911:. Retrieved 2898: 2887:. Retrieved 2877: 2866:. Retrieved 2862: 2853: 2842:. Retrieved 2838: 2829: 2818: 2807:. Retrieved 2803: 2794: 2783:. Retrieved 2779: 2770: 2756: 2745: 2734: 2723: 2702: 2693: 2684: 2669: 2636: 2621: 2612: 2589: 2579:do_something 2546: 2529: 2500: 2460: 2456:optimization 2453: 2333: 2320: 2312: 2302: 2292:do_something 2238: 2170: 2147: 2118: 2101: 2066: 2053: 2036: 2015: 1994: 1967: 1925:And @@ {...} 1891:Visual Basic 1813: 1647: 1622: 1589: 1473: 1449: 1434: 1400: 1332: 1308: 1276: 1212: 1044: 951: 871: 847: 825:(nor), etc. 795: 739: 727:Result type 659: 648: 636: 627: 624: 621: 617: 614: 611: 608: 604: 600: 597: 594: 590: 586: 583: 579: 575: 571: 567: 563: 559: 556: 552: 548: 544: 528: 505: 494: 490: 486: 479: 475: 471: 459:truth-values 456: 451: 446: 442: 438: 431: 427: 421: 417: 413: 403: 399: 396: 379: 373: 369: 365: 361: 357: 353: 345: 341: 337: 333: 331: 327: 323:user-defined 322: 318: 311:side effects 284: 279:exclusive or 277: 243: 202: 198: 194: 193: 155: 112: 103: 93: 86: 79: 72: 60: 48:Please help 43:verification 40: 2632:ray tracing 2600:expressionA 2558:expressionA 2502:POSIX shell 2309:a != 0 2124:IEC 61131-3 2111:false and: 2090:Free Pascal 1929:Or @@ {...} 1910:Select Case 1834:IEC 61131-3 1787:Standard ML 1725:Last value 1689:Last value 1617:POSIX shell 1579:Last value 1414:Last value 1354:Last value 1322:Last value 1298:Last value 1286:&&= 895:Objective-C 794:andf , orf 582:): 524:POSIX shell 321:to achieve 319:proceduring 106:August 2013 3055:Categories 2913:2013-08-24 2889:2019-01-09 2868:2021-08-16 2844:2021-08-16 2809:2019-02-12 2785:2024-04-02 2661:References 2626:on modern 2561:&& 2510:&& 2426:&& 2274:&& 2210:&& 2175:language: 2162:Common use 2025:&& 2021:overloaded 1942:&& 1745:&& 1709:&& 1642:PowerShell 1628:&& 1595:&& 1563:&& 1507:&& 1374:&& 1346:&& 1314:&& 1282:&& 1272:JavaScript 1258:&& 1218:&& 1100:&& 1086:&& 1058:&& 1019:&& 1001:&& 971:&& 957:&& 931:&& 909:&& 877:&& 853:&& 660:Examples: 512:precedence 502:Precedence 393:Definition 348:: compare 76:newspapers 2714:1010.3674 2678:full text 2604:myfunc(b) 2592:myfunc(b) 2305:myfunc(b) 2122:The norm 2042:static if 1791:Un­known 1759:Smalltalk 1098:Boolean ( 1017:Boolean ( 969:Boolean ( 721:operators 620: := 576:operators 549:operators 506:Although 3015:ALGOL 60 2909:. Itu.dk 2649:See also 2504:idioms: 2464:idioms: 2136:AND_THEN 2094:compiler 2059:compiler 1972:Boolean 1950:Boolean 1914:Numeric 1885:Boolean 1857:Boolean 1849:AND_THEN 1827:Boolean 1803:Boolean 1781:Boolean 1753:Boolean 1661:Boolean 1611:Boolean 1543:Boolean 1535:and_then 1515:Boolean 1487:Boolean 1463:Boolean 1445:Modula-2 1439:Numeric 1382:Boolean 1266:Boolean 1226:Boolean 1194:Boolean 1166:Boolean 1138:Boolean 1130:and then 1066:Boolean 885:Boolean 861:Boolean 837:Boolean 821:(nand), 800:Boolean 787:ALGOL 68 781:Boolean 773:and then 753:Boolean 715:Language 595:continue 564:for each 545:function 539:continue 383:—  315:ALGOL 68 213:in some 2429:isalpha 2369:isalpha 2173:C-based 2140:OR_ELSE 1877:AndAlso 1853:OR_ELSE 1795:andalso 1539:or_else 1204:Haskell 1172:Fortran 1158:andalso 1134:or else 1041:(CFML) 777:or else 598:else if 336:" and " 258:Haskell 205:(after 90:scholar 2564:myfunc 2414:return 2366:return 2277:myfunc 2086:Delphi 1897:(VBA) 1881:OrElse 1809:TTCN-3 1799:orelse 1667:Python 1521:Pascal 1469:Oberon 1396:Scheme 1360:Kotlin 1236:MATLAB 1162:orelse 1144:Erlang 1116:Eiffel 829::AndIf 628:result 625:return 618:result 612:result 609:return 605:result 591:result 580:values 574:) in ( 560:result 555:) 553:values 510:takes 291:strict 274:Delphi 92:  85:  78:  71:  63:  2907:(PDF) 2709:arXiv 2396:const 2348:const 2321:false 2313:false 2219:denom 2201:denom 2183:denom 2152:BASIC 2019:When 1959:& 1764:& 1736:& 1700:& 1672:& 1554:& 1493:OCaml 1479:& 1426:& 1420:MUMPS 1328:Lasso 1304:Julia 1249:& 1244:Swift 1208:OCaml 1186:.and. 1177:.and. 1077:& 992:& 923:& 921:int ( 900:& 833::OrIf 719:Eager 688:false 666:false 537:by a 533:over 514:over 493:else 489:then 480:false 478:else 474:then 466:False 445:else 441:then 420:else 416:then 317:used 293:. In 227:false 223:false 201:, or 97:JSTOR 83:books 3010:Lisp 2639:Java 2608:Java 2532:echo 2522:echo 2513:echo 2462:Perl 2423:NULL 2399:char 2387:bool 2351:char 2339:bool 2138:and 2130:and 2107:and: 2088:and 2044:and 2027:and 2000:bool 1968:none 1955:ZTT 1814:none 1773:and: 1731:Rust 1695:Ruby 1653:-and 1648:none 1623:none 1590:none 1549:Perl 1498:land 1474:none 1450:none 1435:none 1422:(M) 1401:none 1388:Lisp 1333:none 1309:none 1277:none 1232:Java 1213:none 1190:.or. 1181:.or. 1045:none 952:none 872:none 867:Bash 848:none 740:none 734:ABAP 615:else 491:true 483:and 464:and 462:True 402:and 370:cand 362:with 354:cand 346:cand 334:cand 301:and 270:Java 254:Perl 250:Lisp 239:true 235:true 69:news 2641:'s 2590:if 2582:(); 2490:die 2487:and 2475:die 2295:(); 2244:int 2228:... 2213:num 2180:int 2128:AND 2006:or 1934:And 1901:And 1868:And 1840:AND 1819:and 1777:or: 1713:and 1681:and 1657:-or 1599:and 1585:PHP 1567:and 1526:and 1502:lor 1455:AND 1406:and 1392:Lua 1365:and 1338:and 1294:||= 1149:and 1121:and 1050:AND 947:C++ 843:awk 806:APL 764:and 759:Ada 745:and 622:val 572:val 557:let 531:AND 508:AND 485:if 470:if 437:if 430:or 412:if 376:C); 374:cor 372:(B 368:C) 366:cor 364:(A 358:cor 356:B) 352:(A 342:cor 338:cor 303:C++ 266:Ada 219:AND 52:by 3057:: 2931:. 2861:. 2837:. 2802:. 2778:. 2692:. 2573:)) 2552:if 2519:|| 2472:or 2438:); 2420:!= 2378:); 2286:)) 2268:!= 2259:if 2204:!= 2195:if 2132:OR 2113:). 2078:^ 2029:|| 1982:^ 1961:, 1946:|| 1944:, 1940:, 1938:Or 1936:, 1927:, 1905:Or 1903:, 1893:, 1879:, 1872:Or 1870:, 1851:, 1844:OR 1842:, 1836:) 1823:or 1821:, 1797:, 1775:, 1766:, 1749:|| 1747:, 1738:, 1721:or 1719:, 1717:|| 1715:, 1711:, 1702:, 1685:or 1683:, 1674:, 1655:, 1632:|| 1630:, 1607:or 1605:, 1603:|| 1601:, 1597:, 1575:or 1573:, 1571:|| 1569:, 1565:, 1556:, 1537:, 1530:or 1528:, 1511:|| 1509:, 1500:, 1483:OR 1481:, 1459:OR 1457:, 1428:, 1410:or 1408:, 1394:, 1390:, 1378:|| 1376:, 1369:or 1367:, 1350:|| 1348:, 1344:, 1342:or 1340:, 1318:|| 1316:, 1292:, 1290:|| 1288:, 1284:, 1262:|| 1260:, 1251:, 1242:, 1238:, 1234:, 1222:|| 1220:, 1206:, 1202:, 1200:Go 1188:, 1179:, 1160:, 1153:or 1151:, 1132:, 1125:or 1123:, 1110:) 1104:|| 1092:, 1090:|| 1088:, 1079:, 1062:|| 1060:, 1056:, 1054:OR 1052:, 1033:) 1031:?? 1029:, 1023:|| 1013:?? 1011:, 1007:, 1005:|| 1003:, 994:, 987:C# 981:) 975:|| 963:, 961:|| 959:, 941:) 935:|| 929:, 925:, 915:, 913:|| 911:, 902:, 893:, 881:|| 879:, 857:|| 855:, 831:, 817:, 813:, 775:, 768:or 766:, 749:or 747:, 736:) 653:, 601:op 587:op 584:if 578:, 570:, 568:op 551:, 541:: 535:OR 516:OR 360:C 272:, 268:, 256:, 252:, 241:. 231:OR 197:, 2966:e 2959:t 2952:v 2935:. 2916:. 2892:. 2871:. 2847:. 2812:. 2788:. 2764:. 2717:. 2711:: 2696:. 2585:} 2576:{ 2570:b 2567:( 2555:( 2493:; 2478:; 2444:} 2435:p 2432:( 2417:p 2411:{ 2408:) 2405:p 2402:* 2393:( 2384:} 2375:p 2372:( 2363:{ 2360:) 2357:p 2354:* 2345:( 2330:. 2298:} 2289:{ 2283:b 2280:( 2271:0 2265:a 2262:( 2256:; 2253:0 2250:= 2247:a 2234:} 2225:{ 2222:) 2216:/ 2207:0 2198:( 2192:; 2189:0 2186:= 2010:. 2008:1 2004:0 1963:| 1768:| 1740:| 1704:| 1676:| 1558:| 1430:! 1253:| 1240:R 1108:? 1102:, 1094:? 1081:| 1072:D 1027:? 1021:, 1009:? 996:| 979:? 973:, 965:? 939:? 933:, 927:| 917:? 904:| 891:C 823:⍱ 819:⍲ 815:∨ 811:∧ 705:. 700:, 695:, 690:: 683:. 678:, 673:, 668:: 655:1 651:0 566:( 495:y 487:x 476:y 472:x 452:x 447:y 443:x 439:x 432:y 428:x 422:x 418:y 414:x 404:y 400:x 299:C 248:( 183:e 176:t 169:v 119:) 113:( 108:) 104:( 94:¡ 87:¡ 80:¡ 73:¡ 46:. 23:.

Index

Short-circuit test

verification
improve this article
adding citations to reliable sources
"Short-circuit evaluation"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
Evaluation strategies
Lazy evaluation
Partial evaluation
Remote evaluation
Short-circuit evaluation
v
t
e
John McCarthy
Boolean operators
programming languages
lazy evaluation
Lisp
Perl
Haskell
Boolean operators
Ada
Java

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑