Fundamentals of Programming Flashcards

1
Q

Algorithm

A

a sequence of steps to complete a task

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

Definite iteration

A

For loop

the number of iterations is known (at the time of execution);

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

Indefinite iteration, condition at the start

A

While loop

Indefinite iteration: the number of iterations depends on a condition (that is tested before / after each iteration);

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

Indefinite iteration, condition at the end

A

Repeat until

Indefinite iteration: the number of iterations depends on a condition (that is tested before / after each iteration);

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

Global variable

A

Global variable can be used anywhere in program // global variable is declared in outmost block / outside subroutines;

global variables use memory the entire time the program is executing;

global variables exist the entire time the program is running;

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

Local variable

A

Local variable can only be used in the block / subroutine in which it is declared;

Local variables only use memory when the program block they are in is executing;

Local variables only exist when the program block they are in is executing;

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

State one difference between local and global variables and give two reasons why it is good practice to use local variables.

A

Difference:

global variables accessible to all parts of the program

// declared in main program block

// local variables declared in subroutine

// accessible only in the program block/subroutine in which it was declared;

Reason:

memory allocated to local variables can be reused when subroutine not in use;

local variable only exists while the program block/subroutine is executing;

using local variables makes subroutines self-contained;

A. prevents accidental changes;

A. easier debugging/maintenance;

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

Why is it good practice to use local variables?

A

1.   makes a subroutine self-contained;

2.   releases storage when subroutine terminates;

3.   able to test / debug subroutine independently;

4.   easier to re-use subroutine in another program;

5.   local variable values cannot be inadvertently/accidentally altered by a subroutine call from the subroutine;

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

Explain one difference between a procedure and a function.

A

Functions always return some value when called;

Procedures may return a value;

Functions appear in expressions;

Procedures do not appear in expressions;

Procedures name alone makes up the statement / call <name></name>

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