loops

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

1/7

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.

8 Terms

1
New cards

loop

a program construct that repeatedly executes the loop’s statements (known as the loop body) while the loop’s expression is true; when false, execution proceeds past the loop. Each time through a loops statements is called an iteration

2
New cards

loop expressions

various kinds of expressions are found in loop expressions. For example, sometimes a loop is executed as long as a value is greater than another value, or less than another value. Sometimes a loop is executed as long as a value is not equal to another value

3
New cards

infinite loop

loop that never stops iterating. A common error is to accidentally create an infinite loop, often by forgetting to update a variable in the body, or by creating a loop expression whose evaluation to false isn’t always reachable

4
New cards

while and for loops

because looping until done and looping N times are so common, most textual programming languages have specific constructs for these types of loops. A while loop is a loop that repeatedly executes the loop body while the loop’s expression evaluates to true. A for loop is a loop consisting of a loop variable initialization, a loop expression, and a loop variable update that typically describes iterating for a specific number of times. Generally a programmer uses a for loop when the number of iterations is known, and a while loop otherwise

5
New cards

nested loop

loop that appears in the body of another loop. The nested loops are commonly referred to as the inner loop and the outer loop. Nested loops have various uses. Below is a nested loop example that graphically depicts an integers magnitude by using asterisks, creating a bar chart. The inner loop is a for loop that handles the printing of the asterisks. The outer loop is a while loop that handles executing until a negative number is entered

6
New cards

do-while loop

loop that first executes in the loop body’s statements, then checks the loop condition. Compared to a while loop, a do while loop is useful when the loop should iterate at least once

7
New cards

for loops

in code, a loop that iterates N times is typically described using a for loop. this is a loop with three parts at the top; a loop variable initialization, a loop expression, and a loop variable update. A for loop describes iterating N times more naturally than a while loop

8
New cards

loops summary

  • A loop is a program construct that repeatedly executes the loop's statements (known as the loop body) while the loop's expression is true; when false, execution proceeds past the loop. Each time through a loop's statements is called an iteration.

  • A common programming task is to use a loop to examine a list of values one value at a time and update variables along the way. Common tasks include computing an average, counting the number of negative items in a list, finding the maximum, etc..

  • Programmers often use loops to execute a computation until a done condition is reached. That done condition is reached when the loop expression is false.

  • An infinite loop is a loop that never stops iterating.

  • A loop iterating a specific number of times commonly consists of three parts: a loop variable initialization before the loop, a decision statement for the loop expression, and a loop variable update at the end of the loop body.

  • A while loop is a loop that repeatedly executes the loop body while the loop's expression evaluates to true.

  • A for loop is a loop that typically describes iterating for a specific number of times. A for loop consists of a loop variable initialization, a loop expression, and a loop variable update statement.

  • A nested loop is a loop that appears in the body of another loop. The nested loops are commonly referred to as the inner loop and outer loop.

  • A do-while loop is a loop that first executes the loop body's statements, then checks the loop condition. Compared to a while loop, a do-while loop is useful when the loop should iterate at least once.