0% found this document useful (0 votes)
32 views1 page

Mangaring, Eugene O. ENG - 158: // While Loop

The document contains C++ code examples demonstrating while, for, and do-while loops. It shows a while loop that prints increasing asterisk patterns on each line. A for loop example prints the same pattern using spaces before the asterisks. Finally, a do-while loop again prints the pattern but with spacing calculated differently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Mangaring, Eugene O. ENG - 158: // While Loop

The document contains C++ code examples demonstrating while, for, and do-while loops. It shows a while loop that prints increasing asterisk patterns on each line. A for loop example prints the same pattern using spaces before the asterisks. Finally, a do-while loop again prints the pattern but with spacing calculated differently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Mangaring, Eugene O.

ENG_158

while ( y < x)
{
cout << X;y++;
}
cout << endl;

// While Loop
#include <iostream>
#include <conio.h>

}
}
while (x < 9);
getch();

using namespace std;


main()
{ int x,y=1,space = 0,i=0;
char X= '*';
x=1;
while (x < 9)
{
if((x%2) != 0)
{ space = (11 - x) / 2;
x++;
while( i <space)
{ cout << " ";
i++;
}
while ( y < x)
{
cout << X;y++;
}
cout << endl;
}

// For Loop
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
int x,y;
char star = 'x';
char space = ' p ';
int temp;
int numSpaces = 0;
for(x=1; x <= 9; x++)
{

}
getch();

if((x%2) != 0)
{

// Do-While Loop
#include <iostream>
#include <conio.h>

for(int i = 0; i < numSpaces; i++)


{
cout << " ";
}

using namespace std;

for(y=1; y <= x ; y++)


{
cout << star; }
cout << endl;

main()
{ int x,y=1,space = 0,i=0;
char X= 'x';
x=1;
do
{ if((x%2) != 0)
{
space = (11 - x) / 2;
x++;
while( i <space)
{cout << " ";
i++;
}

numSpaces = (11 - x) / 2;

}
}
getch();
}

/* Output
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx

You might also like