Java An Introduction to Problem Solving and Programming Chapter 4.2 (Notes)

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

1/6

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:40 PM on 9/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

7 Terms

1
New cards

The Loop Body

• Write down a sequence of actions when designing a loop.

2
New cards

Initializing Statements

• A loop depends on correct initial values.

3
New cards

Controlling the Number of Loop Iterations

• A counter can control a loop's repetition.

• A loop's repetition can be controlled by asking the user whether to continue.

• User can signal the end of repetition by entering a sentinel value.

4
New cards

The break Statement and continue Statement in Loops

• A break statement within a loop ends its iteration.

• A continue statement within a loop ends the current iteration.

• As much as possible, avoid the break and continue Statement in Loops.

5
New cards

Loop Bugs

• Two common loop bugs

- Unintended infinite loops.

- Off-by-one errors.

• Certain data can cause an infinite loop.

• Code should try to guard against user error.

• Off-by-one errors are caused by an incorrect boolean expression.

• Do not compare floating-point values using == or !=.

• Off-by-one errors might be unnoticed.

• Always retest.

6
New cards

Tracing Variables

• Trace variables as their values changes during execution.

• add //* at the end, to keep track of where a trace variable is.

7
New cards

Assertion Checks

• An assertion states a truth if a program's logic is correct.

• An assert statement checks an assertion.

• Assertion checking can be on or off.

• Assert Boolean_Expression;

• You can place an assertion check anywhere in your code. If assertion checking is turned on and Boolean_Expression is false, your program will display a suitable error message and end execution. If assertion checking is not turned on, the assertion check is treated as a comment.