CHAPTER 7

STATEMENT-LEVEL CONTTROL STRUCTURE

 

 

 

COMPOUND STATEMENTS

            begin

                statement_1;

               

                statement_n

             end

 

 

 

SELECTION STATEMENTS

 

Two-Way Selection Statements

            if(flag .ne. 1) go to 20

                 i = 1

                 j = 2

         20    continue

 

 

           

                     if (Boolean expression) then

                          begin

                             statement _1;

                             

                              statement-n

                          end

                      if (Boolean expression) then

                          statement

                      else       

                          statement

 

Nesting Selectors

                     if sum  =  0  then

                           if count   =   0  then

                                  result  :=  0

                     else

                           result  :=  1

                     if sum  =  0  then

                         begin

                            if count  =  0  then

                                 result  :=  0

                            end

                          else

                                 result  :=  1

 

 

MULTIPLE SELECTION CONSTRUCTS

                     IF (arithmetic expression) N1, N2, N3

                     case integer_expression of

                             begin

                                  statement_1;

                                  

                                  statement-n

                             end

 

 

 

-- Pascal’s case

                      case expression of

                             constant_list_1: statement_1:

                             

                             constant_list_n: statement_n

                      end

 

-- The C multiple selector construct, switch, which also appears i C++ and Java:

                      switch (expression)  {

                            case expression_1:  statement_1;

                            

                            case expression_n:  statement_n;

                            [default:  statement_n + 1]

                       }

 

ITERATIVE STATEMENTS

An iterative statement is one that causes a statement or collection of statements to be executed 0 or 1 or more times.  Every programming language has included some method of repeating the execution of segments of code.  Iteration is the very essence of the power of the computer.  If iteration were not possible, programmers would be required to state every action in sequence; useful programs would be large and inflexible and take a huge amount of time to write.

 

COUNTER-CONTROLLED LOOPS

 

THE DO STATEMENT OF FORTRAN 77 & FORTRAN 90

              DO   label variable  =  initial, terminal, [step size]

      Where the label is the last statement in the loop body and the step size, when absent, defaults to 1.

 

LOGICALLY CONTROLLED LOOPS

 

ITERATION BASED ON DATA STRUCTURES

 

UNCONDITIONAL BRANCHING