FINALS Flashcards
are commands that enable a program to “take decisions”, following one path or another.
Control Structures
Control Structures are commands that enable a program to ____________ , following one path or another.
“take decisions
These are the blocks that analyze variables and choose directions in which to go based on given parameters.
Control Structures
3 types of Control Structures
Conditional Structures (or Selection)
Iteration Structures (or Looping)
Selective Structures (switch)
Conditional operator
(? :)
are used to execute one or more statements if a condition is met.
Conditionals (or Selection)
4 types of Conditional Structures
if statements
if else statements
if else if statements
Nested if statements
execute one or more statements when a condition is met. If the testing of that condition is TRUE, the statement gets executed. But if it’s FALSE (the condition is not met), then nothing happens.
If statements
This Control Structure allows a program to follow alternative paths of execution, whether a condition is met or not.
If else statements
can have multiple alternative statements.
If-else if statements
is an if statement that is the target of another if statement.
nested if
Use the s____________ to select one of many code blocks to be executed.
Switch statement
Multiple – Selection Structure
Switch
The switch expression is evaluated how many times?
once
The ______ and ________ keywords are optional.
break and default
When C++ reaches a _________ keyword, it breaks out of the switch block.
break
This will stop the execution of more code and case testing inside the block.
break
This is a keyword that specifies some code to run if there is no case match.
default
refers to Switch statements inside of another Switch Statements.
Nested-Switch statements
Other word for Looping stuctures?
Iterative or Repetition
There may be a situation when you need to execute a block of code several number of times.
Looping Structures (Iterative, Repetition)
In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Looping Structures (Iterative, Repetition)
allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.
A loop statement
Types of Looping Statements
while Loop (Pretest loop)
do while Loop (Post-test loop)
for Loop (Counter-controlled loop)
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
while Loop (pretest loop)
Like a while statement, except that it tests the condition at the end of the loop body.
do while Loop (Post-test loop)
Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
for Loop (Counter-controlled loop)
is a piece of code that lacks a functional exit so that it repeats indefinitely.
Infinite loop or endless loop
Flow of control in for Loop
initialization step
condition / boolean expression
step expression / update statement
condition / boolean expression (until the condition has been met)
is executed first, and only once. This step allows you to declare and initialize any loop control variables and this step ends with a semi colon (;).
initialization step
If it is true, the body of the loop is executed. If it is false, the body of the loop will not be executed and control jumps to the next statement past the for loop.
condition / boolean expression
This statement allows you to update any loop control variables.
step expression / update statement (increment)
The ________________ is now evaluated again. If it is true, the loop executes and the process repeats. After the Boolean expression is false, the for loop terminates.
condition / boolean expression
A loop within another loop
nested loop.
is collection of items stored at contiguous memory locations. The idea is to store multiple items of same type together.
array
is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.
array
Each item in an array is called an __________?
element
and each element is accessed by its _________________?
numerical index.
The index of an array always starts with ?
0
Array Initialization
Initializing values to an array can be done in two ways:
During initialization of the array;
int arrayInt[] = {1,2,3,4,5};
double arrayDouble[] = {2.5,3.2,7.0};
Assigning values by its numerical index;
arrayInt[0] = 2;
arrayInt[1] = 4;
arrayInt[2] = 7;
is an array containing one or more arrays.
multidimensional array
To create a two-dimensional array, add each array within its own set of curly braces:
int myNumbers[columns][rows] = { {1, 2, 3, 4}, {5, 6, 7, 8} };