Repetition Part 2 Flashcards

1
Q

Dont use a loop for

A

alternative choices/ course of action

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

If you have a loop and it should be a branch, you will have a

A

logic error

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

Pseudo Code

A

Looks like a code but just english like statements

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

Types of nesting (3)

A

branch within a loop
Loop within a branch
loop within a loop

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

Branch in a loop:

(2 ex)

A

Ex: assignment A1 (We have a loop for each room and the branches are the menu)
- ex: while the user enter an invalid value for age ( too high/low) an error message is displayed

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

Loop in a branch:

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

loop in a loop

ex

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

modulo operator %

ex+what it is

A

The modulo operation (abbreviated “mod”, or “%” in many programming languages) is the remainder when dividing. For example, “5 mod 3 == 2” which means 2 is the remainder when you divide 5 by 3.

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

The break instruction (2)

When is it used?+ what does it add?

A
  • Used to terminate the repetition of a loop which is seperate from the main Boolean expression
  • Adds another exit point (makes it hard to trace)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Alternatives to a break

A
  • add the second Boolean expression as part of the loop’s main boolean expression (while …. and NOT…..) instead of (while… if … break)
  • Use a flag
The false breaks the loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Infinite loops (3)

What they are+ caused by +ex

A
  • loops that never end
  • ## Can be caused by logical by not error in loop control
Didnt indent last line so control is flawed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly