0% found this document useful (0 votes)
30 views

While Loops

This document discusses while loops, which allow iteration when the number of iterations is unknown. It provides examples of while loops and how to avoid issues like infinite loops. Key points covered include: - While loops are used for iteration when the number of loops is unknown - Infinite loops occur when the test condition is never changed within the loop body - ITM (Initialize, Test, Modify) is important to think about to avoid loop problems - Tests of while loops should execute the loop body 0, 1, and multiple times

Uploaded by

Luca Kab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

While Loops

This document discusses while loops, which allow iteration when the number of iterations is unknown. It provides examples of while loops and how to avoid issues like infinite loops. Key points covered include: - While loops are used for iteration when the number of loops is unknown - Infinite loops occur when the test condition is never changed within the loop body - ITM (Initialize, Test, Modify) is important to think about to avoid loop problems - Tests of while loops should execute the loop body 0, 1, and multiple times

Uploaded by

Luca Kab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Module 10

Iteration

Lecture
While Loops

Module 10 Learning Objectives


Last time, we finished our discussion of for and
foreach loops
This time, well look at while loops, which give us
a way to iterate when we dont know how many
times well need to iterate
In-Lecture Quiz

The loop well use to perform iteration in our C# code
when we dont know how many times to loop is the

A: while loop
B: if loop
C: Hula Loop
D: loopInC# statement
In-Lecture Quiz

An infinite loop occurs when we

A: loop infinitely (duh)
B: let our computer run until the end of time
C: dont change anything in the body of the loop to
affect the test
D: use < instead of <= in our Boolean expression
In-Lecture Quiz

We can avoid lots of loop problems by thinking about ITM,
which means

A: I Taste Monkeys
B: Incas Toast Men
C: Initialize Test Modify
D: Are you (*&%#*# kidding me?
In-Lecture Quiz

When we test a while loop we should execute the loop body

A: 0, 1, and multiple times
B: with C4 and a grapefruit
C: with a sledgehammer and a melon
D: Why? Just why?

Recap
We learned how we can use while loops when we
dont know how many times well need to iterate
End of Module 10
Next Time
Well start working on designing and implementing
our own custom classes

You might also like