Presentation is loading. Please wait.

Presentation is loading. Please wait.

Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.

Similar presentations


Presentation on theme: "Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski."— Presentation transcript:

1 Control Structures (Structured Programming) for controlling the procedural aspects of programming
CS1110 – Kaminski

2 2 Programming Paradigms
PP (Procedural Programming) OOP (Object Oriented Programming) but the body of OOP methods (& constructors & getters & setters) use PP

3 Procedural Programming
Procedure (~= process = ~algorithm) Steps to solve a problem: 1st step 2nd step . . . last step

4 Object Oriented Programming
a class includes: STORAGE for object’s ATTRIBUTES (= variables) - all objects of this class type HAVE these attributes - but each object has different VALUES for the attributes BEHAVIORS (= methods) all objects of this class type can DO these behaviors (when requested) = “services” which this type of object can provide

5 A program consists of… 0) Header code (“just packaging info”) for
[both PP programs & OOP programs] 0) Header code (“just packaging info”) for packages classes methods (& their parameters) import statement (to get classes from library)

6 1) Declarations request memory locations for data storage
give name & data type to each possibly give an initial value (i.e., declare variables & constants & objects)

7 2) Action statements to be executed:
operate on data Arithmetic (on numeric types) * / % Concatenate (string & … types) + move data around memory to memory (assignment) = memory to console (or file or window or …) keyboard (or file or window or …) to memory

8 3) Control statements decide the order that actions execute
- next statement? - skip over some? - repeat some? - transfer control to elsewhere? - & return control back to “here”? NOTE: control STARTS at 1st statement in main method

9 Control Structures Traditionally: sequence – the default
selection (decision, conditional execution) repetition (looping) Also: call method (& go back to where called) goto / break / return (& not go back)

10 Transfer control next statement (in physical sequence) (default)
skip 1+ actions if some condition is FALSE or choose which action(s) to do next from SET of several choices, based on the value of some variable loop to do 1+ actions again (& again & again …) a fixed number of times or until some event happens i.e., when specified condition becomes True (or False) call a method & return “here” when it’s done method itself does some actions & it may itself transfer control further go to some statement & do NOT return “here” when done

11 Sequence start at the top do 1 statement after another, in order
continue til the end

12 Selection (if-then-else)
condition’s result (as true or false) determines which of 2 paths to follow (1 or more statements in each path)

13 Looping repeat 1+ statements based on whether a condition is
true or false Condition may be: - event - a counter loop UNTIL condition becomes true, then stop looping WHILE condition is true, keep looping – stop looping when false

14 Types of Loops while loop (in most languages, incl. Java)
for loop (in most languages, incl. Java) do until loop (in some languages, NOT Java) do while loop (in some languages, incl. Java) go to loop [bad programming practice] infinite loop with break [bad programming practice]

15 Combine the control structures
Stack them or Nest them


Download ppt "Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski."

Similar presentations


Ads by Google