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
if…else Double-Selection Statement
- Performs one action when the condition is true and a different action when the condition is false
- The conditional operator is Java’s only ternary operator
All Programs can be written in terms of three types of control structures: _____ ______ and _____
- Sequence
- Selection
- Reptition
The _____ statement is used to execute one action when a condition is true and another when the condition is false.
if…else statement
Repeating a set of instructions a specific number of times is called ______ repetitiion.
Counter-Controlled
or
Definite
When it’s not known in advance how many times a set of statements will be repeated, a(n)_____ value can be used to terminate repetition.
sentinel
signal
flag
dummy
The _____ structure is built into Java; by default, statements execute in the order they appear
sequence structure
Instance variables of types char, byte, short, int, long, float and double are all given the value _____ by default
0 (zero)
Java is a(n)______ language; it requires all variables to have a type.
strongly typed
If the increment operator is ______ to variable, first the variable is incremented by 1, then its new value is used in the expression
prefixed