// Console_ForLoops1.cpp : main project file. /* ________________________________________________ Learning C++: Lesson 4 Counting Things with For Loops Ron Kessler Created 5/22/2016 This little program shows how to use for loops to repeat blocks of code when you know how many times you need to repeat. This is called a "counted loop". _________________________________________________ */ #include "stdafx.h" using namespace System; int main(array ^args) { //---make a loop that starts with 1 and runs 5 times for (int counter = 1; counter <= 5; counter++) //we use an int to manage the loop. We are incrementing by 1 { Console::WriteLine(counter); //print out the value of our LCV each iteration } Console::WriteLine("\n\nPress any key to count by 2's."); Console::ReadLine(); //keeps the window/console open //---now count by 2's for (int counter = 0; counter <= 20; counter+=2) //we use an int to manage the loop. We are incrementing by 1 { Console::WriteLine(counter); //print out the value of our LCV each iteration } Console::WriteLine("\n\nNow let's count backwards from 30 by 5's."); Console::ReadLine(); Console::Clear(); //---now count backwards by 5's for (int counter = 30; counter >= 0; counter -= 5) //we use an int to manage the loop. We are incrementing by 1 { Console::WriteLine(counter); //print out the value of our LCV each iteration } Console::WriteLine("\n\nAny key to end."); Console::ReadLine(); }