Ch. 4 Control Statements Flashcards
Before writing a porgram to solve a problem.
- You must have a thorough understanding of teh problem and a carefully planned approach to solving it.
- You must also understand the building blocks that are avaiable and employ proven program construction techniques
Any computing problem can be solved by….
Executing a series of actions in a specific order.
ALGORITHM
Procedure for solving a problem in terms of the actions to execute and the order in which they execute is called an algorithim.
Program Control
Specifying the order in which statements execute in a program is called program control.
Pseudocode
An informal language that helps you develop algorithms without having to worry about the strict details of java language syntax
Similar to everyday english, its convenient to user friendly, but it’s not an actual computer programing language
Helps you “think out” a program before attempting to write it in a programing language such as java.
Carefully prepared pseudocode can easily be converted to a corresponding java program.
Sequential Execution
Statements in a program executed one after the other in which they’re written
Transfer of Control
Various Java statements enable you to specify that the next statement to execute is not necessarily the next one in sequence.
Control Structure
- Comes from the field of computer science
- The Java Language Specification refers to “control structures” as “control statements”
Selection Statements
- The if statement either performs (selects) an action, if a condition is true, or skips it if it is false.
- 3 Types: Single-Selection, Double Selection Statement, Multiple Selection Statement
Java provides the while, do…while and for repetition (looping) statements
- Enable programs to perform statements repeatedly as long as a loop-continuation condition remains true
The while and for statements
perform the actions in….
- Their bodies zero or more times - if the loop continuation condition is initially false,the action will not execute.
- The do…while statement performs the action(s) in its body one or more times.
The words:
if
else
switch
while
do
for
- Java keywords
- Keywords can not be used as identifiers, such as variable names
Every program is formed by…
Combining as many sequence, selection, and repetition statements as is appropriate for the algorithim the program implements.
if Single-Selection Statement
- Programs use selection statements to choose among alternative courses action
- The if statement is a single-entry/single-exit control statement
Control Statement Stacking
Single-entry/single exit control statements are attached to one another by connecting the exit point of one to the entry point of the next.
Control statement may also be nested inside another control statement