{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter 10 - Chapter10 Repetition Loops iteration ForLoops...

This preview shows pages 1–8. Sign up to view the full content.

Chapter 10 Repetition

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Loops Use loops to repeat the same code many  times with small modifications to each  iteration.
For-Loops Syntax: for (command; boolean_exp; command) { //code to be executed } Example: int x = 1; for (int i=10; i>-1; i--) { x = x * i; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
For-Loops The first command always gets executed  once.  The second command and the code in the  body only get executed while the  expression is true
Loops Each pass through the body of the loop is  one  iteration . //This loop iterates 0 times for (int i=0; i<0; i++){ } //This loop iterates 20 times for (int i=0 i<20; i++){ }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Counting Loops The for-loop is known as a  counting-loop   because you (theoretically) know how  many times it will execute just by looking  at the declaration.
Except… It is totally possible to break out of a for- loop early: for (int i=0; i<20; i++) { i = 20; } //or for (int i=0; i<20; i++) { break; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 15

Chapter 10 - Chapter10 Repetition Loops iteration ForLoops...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online