Topic 3: Conditional Statements & Loops

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

Q: What is a conditional statement in Java?

A conditional statement is used to perform different actions based on different conditions, such as if, else if, and else.

2
New cards

Q: What is the syntax of an "if" statement in Java?

if (condition) { // code to execute if condition is true }

3
New cards

Q: What is the purpose of an "else" statement?

The "else" statement is used to execute a block of code when the "if" condition is false.

4
New cards

Q: What is an "else if" statement?

It allows testing multiple conditions in sequence when the initial "if" condition is false.

5
New cards

Q: What is the difference between "if" and "switch" statements in Java?

"if" is used for evaluating complex conditions, whereas "switch" is more efficient for checking a variable against many possible values.

6
New cards

Q: What is a "switch" statement?

A "switch" statement allows a variable to be tested for equality against a list of values (cases).

7
New cards

Q: What are logical operators used in conditional statements?

&& (AND), || (OR), ! (NOT)

8
New cards

Q: What is a loop in Java?

A loop allows a block of code to be executed repeatedly based on a condition, like "for", "while", or "do-while".

9
New cards

Q: What is the difference between a "for" loop and a "while" loop in Java?

A "for" loop is generally used when the number of iterations is known, while a "while" loop is used when the number of iterations is unknown.

10
New cards

Q: What is the syntax of a "for" loop in Java?

for (initialization; condition; update) { // code to execute }

11
New cards

Q: What is a "while" loop?

A "while" loop executes a block of code as long as the given condition is true.

12
New cards

Q: What is a "do-while" loop?

A "do-while" loop executes the block of code at least once before checking the condition.

13
New cards

Q: What is the "break" statement in Java?

The "break" statement is used to exit a loop or switch statement prematurely.

14
New cards

Q: What is the "continue" statement in Java?

The "continue" statement skips the current iteration of a loop and proceeds to the next iteration.

15
New cards