#include <iostream>
usingnamespace std;
int main()
{
int data1, data2, data3;
cout << "Enter the first number: ";
cin >> data1;
cout << "Enter the second number: ";
cin >> data2;
cout << "Enter the third number: ";
cin >> data3;
for (int i = 1; i <= data1; ++i)
cout << "*";
cout << " " << data1 << endl;
for (int i = 1; i <= data2; ++i)
cout << "*";
cout << " " << data2 << endl;
for (int i = 1; i <= data3; ++i)
cout << "*";
cout << " " << data3 << endl;
}
The output of the code is
***** 5
********* 10
************** 15
But when i put braces in while block like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
for (int i = 1; i <= data1; ++i)
{
cout << "*";
cout << " " << data1 << endl;
}
for (int i = 1; i <= data2; ++i)
{
cout << "*";
cout << " " << data2 << endl;
}
for (int i = 1; i <= data3; ++i)
{
cout << "*";
cout << " " << data3 << endl;
}
The output goes to the new line every iteration of the loop and when i omit the endl i know it endl is puts a new line and forces the output buffer but my question is that i have no idea how braces effect the loop my question is why the output is changed when i put braces on while loop body.