Dec
26
2017

Session VI : Statement-Level Control Structures

In this Session VI : Statement-Level Control Structures , there are 2 sub topics :

  • Selection Statements
  • Iterative Statements

Computations in imperative-language programs are accomplished by evaluating expressions and assigning the resulting values to variables. However, there are few useful programs that consist entirely of assignment statements. At least two additional linguistic mechanisms are necessary to make the computations in programs flexible and powerful: some means of selecting among alternative control flow paths (of statement execution) and some means of causing the repeated execution of statements or sequences of statements. Statements that provide these kinds of capabilities are called control statements.

Selection Statements

A selection statement provides the means of choosing between two or more execution paths in a program. Such statements are fundamental and essential parts of all programming languages, as was proven by Böhm and Jacopini. Selection statements fall into two general categories: two-way and n-way, or multiple selection.

The general form is :

if control_expression

  then clause

  else clause

If the then reserved word or some other syntactic marker is not used to introduce the then clause, the control expression is placed in parentheses. In C89, C99, Python, and C++, the control expression can be arithmetic, in most other languages, the control expression must be Boolean, in many contemporary languages, the then and else clauses can be single statements or compound statements, in Perl, all clauses must be delimited by braces (they must be compound), in Fortran 95, Ada, Python, and Ruby, clauses are statement sequences .

Iterative Statement

Iterative Statement is the repeated execution of a statement or compound statement is accomplished either by iteration or recursion,  and it is one that causes a statement or collection of statements to be executed zero, one, or more times. An iterative statement is often called a loop

The body of an iterative statement is the collection of statements whose execution is controlled by the iteration statement. We use the term pretest to mean that the test for loop completion occurs before the loop body is executedand posttest to mean that it occurs after the loop body is executed. The iteration statement and the associated loop body together form an iteration statement. In addition to the primary iteration statements, we discuss an alternative form that is in a class by itself: user-defined iteration control.

Conclusion

We have described and discussed a variety of statement-level control structures. A brief evaluation now seems to be in order. First, we have the theoretical result that only sequence, selection, and pretest logical loops are absolutely required to express computations. This result has been used by those who wish to ban unconditional branching altogether. Of course, there are already sufficient practical problems with the goto to condemn it without also using a theoretical reason. One of the main legitimate needs for gotos—premature exits from loops—can be met with highly restricted branch statements, such as break.

Written by stevenbudinata in: Uncategorized |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress. Kredit, Streaming Audio | Theme by TheBuckmaker.