4-IfsAndWhiles

4-IfsAndWhiles - Initializing at the type definition int x...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Initializing at the type definition int x = 0; string greeting = “Hello”; bool status = true;
Background image of page 1

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

View Full DocumentRight Arrow Icon
The "if. .else" statement if ( a == b ) { // do this } else { // do that } comparison
Background image of page 2
"logical" comparisons if ( a == b ) if ( a != b ) if ( a < b ) if ( a > b ) if ( a <= b ) if ( a >= b )
Background image of page 3

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

View Full DocumentRight Arrow Icon
note the { } paragraph and no ; if ( a == b ) // then…. { do stuff }
Background image of page 4
Reading Chapter 3: variables skip Chapter 4 Chapter 5: loops up to pg 213
Background image of page 5

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

View Full DocumentRight Arrow Icon
the cmath library #include <cmath> http://www.cplusplus.com/reference/clibrary/cma
Background image of page 6
Iteration
Background image of page 7

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

View Full DocumentRight Arrow Icon
Iteration Repeatedly execute the same, bracketed section of C++ code Execute until certain conditions are met while loops (two types) - loop until a condition is met “for” loops - loop a defined number of times
Background image of page 8
loop while a condition is “true” while ( x < 6 ) { ..... while ( input == false ) { ..... while ( true ) // loops forever { .....
Background image of page 9

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

View Full DocumentRight Arrow Icon
while loop int LoopCounter = 0 ; while ( LoopCounter < 6 ) { LoopCounter = LoopCounter + 1 ; } std::cout << LoopCounter; then, on screen… LoopCounter is: 6
Background image of page 10
Iteration - the “do-while” loop loop while a condition is “true” do { // repeated code here } while (wantToQuit == false);
Background image of page 11

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

View Full DocumentRight Arrow Icon
leaving a loop break; // program falls out of immediate // brackets return 0; // exits main (i.e. the PROGRAM)
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

4-IfsAndWhiles - Initializing at the type definition int x...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online