Sunday, 5 April 2015

8.0 Control Statements & structures.

Intro 

Control statements 
 -Satements that allow for alternative control flow paths  and others  causing the repeated execution of sequences of statements.
- allow programs to be flexible and powerful

Control Stucture
- Is a control statement and the  collection of statements whose execution it controls.


8.2 Selection Statements
-  A selection statement provides the means of choice between two or more execution paths in a program.

  • two-way/n-way category   i.e (2 -way) if then else,   (n-way) if then if then, else
  • multiple-way selectors (multiple selection) C++, java not so much C#

8.2.1  Two Way Selection Statements

If  control_expression
then clause
else clause


*note the expression immediately after the if keyword is called a control expression 

Nested selectors  - are just selection statements in selection statements. an if statement within an if statement

8.2.2  Multiple- Selection Statements

- Allow the selection of one or any number of statements.
- C+=  java not C# - allow execution of more then one segment

var a = 9
switch (a)
    case 9
        a  = a + 3     ' now eqauls 12
   case 11
     break
   case 12  <---while hit here too
    break

C# with statements different from c-base processors as they disallows implicit execution of more than one segment. each segment has to end with a break statement.



8.2 Iterative Statements
An iterative statement is one that causes a statement or collection of statement to be executed zero, one or more times. often called a loop.

ie. for statement, foreach statement, while statement

  

No comments:

Post a Comment