Module 3: Program Flow Flashcards

1
Q

Describe structured programming.

A

Structured programming came about as a way of clarifying code to help increase the quality of code that was written and to also reduce the amount of time if took to create and maintain applications—because you didn’t have to worry about getting lost in the spaghetti code. As the name suggests, code written in this manner has a structure to it. The structure consists of discrete components known as blocks of code. These blocks of code form the functionality of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the purpose of structured programming.

A

When a problem set is too large to solve all at once, you need to break up the problem into smaller pieces that are more manageable.
Breaking down the functionality into the smallest chunks possible will allow you to focus on specific aspects of the application. This allows you to build the functionality in discrete pieces. These discrete pieces form the structure of the program. These discrete pieces are the blocks of code that will execute. These blocks of code do not have to exist in a sequential manner for the program to execute. However, the code blocks are easy to locate in the code and are easy to decipher, making the application code easier to write and maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe branching.

A

You can create branching within code by using discrete blocks of functionality that might be loops or functions. You can have different execution paths that deviate from a sequential path. The execution path can go to any location in the code and the segments that are branched can be short or long.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe how a computer tracks code execution in branching scenarios.

A

Each time a function is called, the code branches to that function and executes the code found there. However, after a branch is complete, the code needs to come back to the function or line of code that called the function that just executed. The computer gets this information from instruction pointers, and it stores these instruction pointers in a special location in the memory known as a stack. The stack is a logical memory area and not a separate physical set of memory chips. all the data associated with a function and the instructions are loaded onto the memory stack. When one function calls another, the stack holds the instruction pointer at the top of the stack for this instruction. The computer knows where the called function resides in memory and it places that memory location on the stack, immediately on top of the pointer for the calling line of code. Then, it loads any data from the called function, executes the instructions there, and then begins to remove the instructions and data from the stack as the execution of that function completes. When the function is complete, all the data is removed from the stack leaving the top item as the last instruction that was executed. This is how a computer knows where to go when branching occurs and how to get back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The Purpose of a Function.

A

Functions provide programmers with a mechanism for creating small pieces of functionality in code that are easy to debug and reuse. They also form the core of structured programming. Functions are also critical to understanding the OOP aspects of this course. They should focus on a single purpose and create named locations for code branching.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Function Definitions.

A

Functions, like everything else in a programming language, have a specific structure. The structure consists of a function’s signature, (sometimes also referred to as the definition) and a function’s implementation. The signature of a function is what makes it unique in the program’s source code while the implementation for the function is the actual body of code that makes up its functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain how computers make decisions.

A

if statements- allow decision making in code. Evaluates conditions, returns true or false based on condition evaluation, controls program flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly