chapter 5: loops

Download Chapter 5: Loops

Post on 23-Feb-2016

47 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Chapter 5: Loops. Outline. Increment and Decrement while loop do-while loop for loop. Slide 5- 2. The Increment and Decrement Operators . ++ is the increment operator. It adds one to a variable. val ++; is the same as val = val + 1; - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

Chapter 5:

Loops

Slide 5- 2OutlineIncrement and Decrementwhile loop do-while loop for loopSlide 5- 3The Increment and Decrement Operators ++ is the increment operator.

It adds one to a variable.

val++; is the same as val = val + 1;

++ can be used before (prefix) or after (postfix) a variable:++val; val++;Slide 5- 4The Increment and Decrement Operators-- is the decrement operator.

It subtracts one from a variable.

val--; is the same as val = val - 1;

-- can be also used before (prefix) or after (postfix) a variable:--val; val--;Slide 5- 5

(Program Continues)Slide 5- 6

Slide 5- 7Prefix vs. Postfix ++ and -- operators can be used in complex statements and expressionsIn prefix mode (++val, --val) the operator increments or decrements, then returns the value of the variableIn postfix mode (val++, val--) the operator returns the value of the variable, then increments or decrementsSlide 5- 8Prefix vs. Postfix - Examplesint num, val = 12;

cout

Recommended

View more >