how to change from for loop to while loop

#include<iostream>
using namespace std;
int main()
{
int length;

cout << "Enter the length of the hollow square\n";
cin>>length;
for(int i=0; i<length; i++)
{
for(int j=0; j<length; j++)
{
if(i==0 || i==length-1 || j==0 || j==length-1)
cout << "*";
else
cout << " ";

}
cout<<endl;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
	int length = 10;
	int i;

	for (i = 0; i < length; ++i) {
		cout << i << endl;
	}

	cout << endl << endl;

	i = 0;
	while (i < length) {
		cout << i << endl;
		++i;
	}
}
Topic archived. No new replies allowed.