CONTROL STRUCTURES IN JAVA

0.0(0)
Studied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:10 AM on 11/4/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

26 Terms

1
New cards

Control Structures

Statements that control the flow of execution in a program. They allow decisions, repetitions, and jumps in the program sequence.

2
New cards

Types of Control Structures

Java has three main types of control structures:

  1. Selection – decision-making (if, if-else, switch)

  2. Repetition – looping (while, do-while, for)

  3. Branching – flow control (break, continue, return)

3
New cards

Selection Statements

Decision-making statements used to control which set of instructions should be executed based on conditions. Includes if, if-else, and switch statements.

4
New cards

if Statement

Executes a block of code only if a given condition is true.
Example:

if (a % 2 == 0) {
   System.out.println("Even number");
}

5
New cards

if-else Statement

Executes one block of code if the condition is true and another block if the condition is false.
Example:

if (a % 2 == 0)
   System.out.println("Even");
else
   System.out.println("Odd");

6
New cards

switch Statement

Used for decision-making when a variable has multiple possible values. It is an easier alternative to multiple if-else statements.
Example:

switch (day) {
   case 1: System.out.println("Monday"); break;
   case 2: System.out.println("Tuesday"); break;
   default: System.out.println("Invalid");
}

7
New cards

case Keyword

Defines each possible value for a switch variable and the code block that executes when matched.

8
New cards

break in Switch

Terminates the current case in a switch statement, preventing the code from “falling through” to the next case.

9
New cards

default Keyword

A case in the switch statement that executes when none of the other case values match.

10
New cards

Rules for switch Statements

  • Case constants must be unique.

  • Data type of cases must match the switch variable.

  • default is optional but should be last.

11
New cards

Repetition Statements

Used to repeat a block of code multiple times as long as a condition is true. Also called loops.

12
New cards

Loop Control Variable

The variable that determines how many times a loop runs, usually appearing in the loop condition.

13
New cards

while Loop

A pre-test loop that repeats code while the condition is true. The condition is checked before each iteration.
Example:

int i = 1;
while (i <= 5) {
   System.out.println(i);
   i++;
}

14
New cards

do-while Loop

A post-test loop that executes the block once before checking the condition. Ensures the loop body runs at least once.
Example:

int j = 1;
do {
   System.out.println(j);
   j++;
} while (j <= 10);

15
New cards

for Loop

A loop used when the number of repetitions is known. It combines initialization, condition, and update in one line.
Syntax:

for (init; condition; update) {
   statement;
}

16
New cards

Components of a for Loop

  • Initialization – sets starting value

  • Test/Condition – determines whether loop continues

  • Increment/Decrement – updates loop variable after each iteration

17
New cards

Common for Loop Mistake

Adding a semicolon right after the for statement causes the loop to execute incorrectly or skip its block.

18
New cards

Iteration

One complete execution of a loop’s body.

19
New cards

Branching Statements

Statements that transfer control to another part of the program. Includes break, continue, and return.

20
New cards

break Statement

Exits a loop or switch statement immediately. It stops the current control structure’s execution.

21
New cards

Labeled Break

A form of break statement that allows you to exit from an outer loop in nested loops.

22
New cards

continue Statement

Skips the rest of the current loop iteration and moves to the next iteration of the loop.

23
New cards

return Statement

Ends a method’s execution and optionally sends a value back to the method’s caller.

24
New cards

Forms of return Statement

  • return value; → returns a value

  • return; → returns nothing (used in void methods)

  • return expression; → returns an evaluated value

25
New cards

Example of return Usage

public static void hello() {
   System.out.println("Hello " + welcome());
}
static String welcome() {
   return "Welcome to Java Programming";
}

26
New cards

Nested Loop

A loop placed inside another loop. Commonly used in multiplication tables or matrix operations.

Explore top notes

note
ap gov unit 1 vocab
Updated 1150d ago
0.0(0)
note
Seaweeds
Updated 1392d ago
0.0(0)
note
Unit 2: Age of Reformation
Updated 1075d ago
0.0(0)
note
meiosis and mitosis
Updated 423d ago
0.0(0)
note
Chapter 25: Nuclear Changes
Updated 1026d ago
0.0(0)
note
Technical Understanding
Updated 598d ago
0.0(0)
note
DEMOCRACY+PARTICIPATION:
Updated 1090d ago
0.0(0)
note
ap gov unit 1 vocab
Updated 1150d ago
0.0(0)
note
Seaweeds
Updated 1392d ago
0.0(0)
note
Unit 2: Age of Reformation
Updated 1075d ago
0.0(0)
note
meiosis and mitosis
Updated 423d ago
0.0(0)
note
Chapter 25: Nuclear Changes
Updated 1026d ago
0.0(0)
note
Technical Understanding
Updated 598d ago
0.0(0)
note
DEMOCRACY+PARTICIPATION:
Updated 1090d ago
0.0(0)

Explore top flashcards

flashcards
Mod Civ 10.3-11.2 study
92
Updated 731d ago
0.0(0)
flashcards
Latin vocab
450
Updated 112d ago
0.0(0)
flashcards
vet it vad ska kalla😘
27
Updated 294d ago
0.0(0)
flashcards
Gov Unit 3 vocab
29
Updated 467d ago
0.0(0)
flashcards
Drug Info Exam 3
268
Updated 124d ago
0.0(0)
flashcards
Citizens - Klein
78
Updated 1046d ago
0.0(0)
flashcards
Modern Art Exam 2: Dates
29
Updated 1083d ago
0.0(0)
flashcards
Mod Civ 10.3-11.2 study
92
Updated 731d ago
0.0(0)
flashcards
Latin vocab
450
Updated 112d ago
0.0(0)
flashcards
vet it vad ska kalla😘
27
Updated 294d ago
0.0(0)
flashcards
Gov Unit 3 vocab
29
Updated 467d ago
0.0(0)
flashcards
Drug Info Exam 3
268
Updated 124d ago
0.0(0)
flashcards
Citizens - Klein
78
Updated 1046d ago
0.0(0)
flashcards
Modern Art Exam 2: Dates
29
Updated 1083d ago
0.0(0)