Download presentation
Presentation is loading. Please wait.
1
Intro to Computer Science Loops
Dr. Olivera Grujic USC
2
Loops?
3
Loops?
4
Computer Science Loop Control flow statement for specifying iteration, which allows code to be executed repeatedly.
5
While Loop in C++
6
While Loop in C++
7
While Loop in C++ Initialization Condition Update
8
Problem with While Pattern
Hard to see all you need to know how the loop progresses Easy to be so engrossed in writing the body of the loop that you forget to increment
9
For Loop in C++
10
For Loop in C++ Condition Update Initialization
11
You Don’t Have to Count Upward!
12
You Don’t Have to Update by 1!
13
DoWhile Loop
14
DoWhile Loop Initialization Update Condition
15
What Does This Code Print?
16
Let’s Rewrite Outer Loop to DoWhile
17
Let’s Rewrite Outer Loop to DoWhile
18
Code Examples
19
Loop Through Strings
20
Verify Phone Number Has 10 Digits
21
Calculates x to the power of n
22
Implements “hotPotato”
Function takes 2 strings Returns false if both strings are empty If either or both strings are non-empty, swaps the values of strings
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.