Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // More Tutorials at Brandonhok.com
- #include <iostream>
- // There are a total 3 looping structures in C++
- // While, for, do...while
- // So, what does a loop has?
- // The name of control variable / loop counter
- // Loop-coninuation condition
- // increment or decrement control variable
- int main()
- {
- // Code Set 1
- // Examine what is a 'while' statement
- int counter = 0; // loop counter
- while (counter < 5) // condition
- {
- std::cout << "Popcorn power" << std::endl;
- ++counter; // increment variable
- }
- // Code Set 2
- // Now check out the 'for' statement
- for (int counter = 1; counter <= 10; counter++)
- {
- std::cout << "This is MEGA! \n";
- }
- // Code Set 3
- // Write down the similarities between 'do...while' and 'while'
- int counter2 = 0;
- do
- {
- std::cout << "This is how we do it";
- ++counter2;
- } while (counter2 <= 10);
- // Try making some of your own code now
- // A good challenge is seeing if you can get an 'if' statement working
- // with these.
- // How about using true and false?
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement