Control Flow Statements Flashcards

1
Q

Type Casting

A
  • when you convert a value from one primitive data type to another type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Widening Casting

A
  • converts a smaller type to a larger size type

- done automatically

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

Narrowing Casting

A
  • converts a larger type to a smaller size type
  • it can be done manually by placing the type in parenthesis in front of the value

code example

double myDouble = 9.78d;
int myInt = (int) myDouble;

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

What is the four key control flow statements in Java?

A
  • switch
  • for
  • while
  • do-while
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

switch statement

A
  • used to select one of many code blocks to be executed.
  • syntax:
switch (expression) {
  case  x:
      // code block
      break;
  case  y:
      // code block
      break;
  default:
      // code block
      break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

for statement

A

syntax:

for (init; condition; increment) {
    // statements
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

while statement

A

syntax:

while (condition) {
    // statements
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

do-while statement

A
do {
    // statements
} while (condition);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

continue

A
  • continue with a loop (bypass all other code in the block/body)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

continue

A
  • when it is used within a loop, the loop bypasses all other code in the block/body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

break

A
  • it can be used to exits the loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the difference between while and do-while statements?

A
  • while loop checks the condition at the start before executing the block
  • do-while loop executes the code block at least once and then the condition is checked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly