7. For Loops Flashcards

1
Q

incrementing and decrementing variable values

A

use ++ or –

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

++

A

increment operator

x++ is equivalent to x = x + 1

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

A

decrement opereator

x– is equivalent to x = x - 1

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

syntax of for loop example

A

for (i = 1; i <= n; i++) {
..
..
}

can also initialise i in the () brackets

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

eg. do something 100 times

A

for (int i = 0; i < 100; i ++)

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

general form of for statement

A

for (initial statement; loop condition; update statement) {
statement(s)
}

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

infinite loops

A

infinite loops should also be avoided like for while loops

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

while vs for loops

A

use FOR when problem can be formulated as:

  • for each integer from i to k
  • for each element in list
  • for each entry in array

use WHILE if FOR doesn’t fit the bill

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

Nested loops

A

we freq need to nest one loop inside another

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