Loops Flashcards

1
Q

Programming constructs

A
  • They can be defined as types of statements in a programming language.
  • Sequence, Selection and Iteration are the three types of programming constructs that are provided in every programming language to support sequence, selection and iteration.
  • In a program, statements may be executed sequentially, selectively or iteratively
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For loop

A

A “for loop” is a repetition control structure
that allows you to repeatedly execute one or
more statements a specific number of times.

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

Entry controlled loop

A

A loop in which the body of the loop is executed only if the test expression is true.

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

Infinite loop

A

An infinite loop is basically a loop that runs
indefinitely. It normally occurs if the test
condition is always true. It results in a logical
error.

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

Empty loop

A

If a loop does not contain any statement in its

loop-body, it is said to be an Empty loop.

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

Purpose of empty loops

A

Empty loops can be used as Timer loops and also

for making the code more compact.

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

While loop

A

 The while loop continually executes a block
of statements while a particular condition
is true.
 In a while loop, a loop control variable should
be initialized before the loop begins, as an
uninitialized variable cannot be used in the
expression in the while statement.
 The loop variable should be updated inside
the body of the while loop.

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

Comparison of for and while

A

Similarity:
Both are Entry-controlled loops.
Difference:
In a ‘for’ loop construct, initialization,
conditional expression and update statement
can be in the loop statement, whereas in a
‘while’ loop construct, only the conditional
expression can be in the loop statement

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

Do…while

A

A loop that is similar to the while loop except that the do while loop is guaranteed to execute at least once

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

Exit controlled loop

A

A loop in which the conditions are tested after at least one iteration of the loop body

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

Difference between while and do while loop

A

While Do while
Entry controlled Exit conrolled

Boolean expression before Boolean expression after
loop body loop body

Statements are executed only Statements are executed
if the expression is true. at least once and they
are executed again if they
are true.

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