Make web site - Chapter 4 Control Structures: Part 1 131

Chapter 4 Control Structures: Part 1 131 Various C# statements enable the programmer to specify that the next statement to execute may be other than the next one in sequence. This is called transfer of control. Many programming complications in the 1960 s were a result of misusing the goto statement, which allows the programmer to specify a transfer of control to one of a wide range of possible destinations in a program. The notion of structured programming became almost synonymous with goto elimination. Bohm and Jacopini s work demonstrated that all programs could be written in terms of only three control structures namely, sequence, selection and repetition. The sequence structure is built into C#. Unless directed otherwise, the computer executes C# statements one after the other in the order in which they appear. A flowchart is a graphical representation of an algorithm or of a portion of an algorithm. Flowcharts are drawn using symbols, such as rectangles, diamonds, ovals and small circles; these symbols are connected by arrows called flowlines, which indicate the order in which the algorithm s actions execute. The if selection structure performs (selects) an action if a condition is true or skips the action if the condition is false. The if/elseselection structure performs an action if a condition is true and performs a different action if the condition is false. A single-selection structure is one that selects or ignores a single action. A double-selection structure is one that selects between two actions. A multiple-selection structure is one that selects among many actions. Keywords are reserved by the language to implement various features, such as C# s control structures. Keywords cannot be used as identifiers. Each program is formed by combining as many of each type of C# s eight control structures as is appropriate for the algorithm the program implements. Single-entry/single-exit control structures make it easy to build programs. The control structures are attached to one another by connecting the exit point of one control structure to the entry point of the next. This is called control-structure stacking. Algorithms in C# programs are constructed from only eight different types of control structures combined in only two ways. The decision symbol has two flowlines emerging from it. One indicates the direction to be taken when the expression in the symbol is true; the other indicates the direction to be taken when the expression is false. Control structure flowcharts contain (besides small circle symbols and flowlines) only rectangle symbols to indicate the actions to be performed and diamond symbols to indicate decisions to be made. This is the action/decision model of programming. The ternary conditional operator (?:) is closely related to the if/else structure. The operands and the ?: form a conditional expression. The first operand is a condition that evaluates to a bool value, the second is the value for the conditional expression if the condition evaluates to trueand the third is the value for the conditional expression if the condition evaluates to false. Nested if/else structures test for multiple cases by placing if/else structures inside other if/ else structures. A set of statements in a pair of braces is called a block. A block can be placed anywhere in a program that a single statement can be placed. A syntax error is caught by the compiler at compile time, while a logic error has its effect during execution.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

Leave a Reply