Terry E Snyder Jr
&  
RemoteWebs.com  

Computer & Web Solutions

Support, Design, and more...
| | |
December 23rd, 2024 12:15:27 PM

The for Loop

Syntax

for (variable initializations; conditional value; variable increment)
{
    //code
}

Examples

for(int i=0; i<10; i++)
{
   cout << "i = " << i;

}

int sum;
for(int i=0, sum = 1; i<20; i++, sum += sum + i);
cout << sum << endl;

int sum = 1;
for(int i=0; i<20; i++)
{
   sum += sum + i;
}
cout << sum << endl;

The do while Loop

Syntax

do

{

  //code

} while(conditional value);

Examples

int sum = 1, i = 0;
do
{
	 sum += sum +i;
	 i++;
} while ( i < 20);
cout << sum;
	

The while Loop

Syntax

while(conditional value)

{

  //code

}

Examples

	int sum = 1, i = 0;
	while( i < 20)
	{
		sum += sum + i;
		i++;
	}
	cout << sum;
	

 

Google
 
Web www.terryesnyderjr.com
www.remotewebs.com

Page Updated on August 23, 2020 22:47

www.terryesnyderjr.com Copyright 2000-2024©