// for loop some some examples( coding and output)
case 4 :
#include<iostream.h>
#include<conio.h>
void main()
{
for(int i=8;i>=0;i--)
cout<<i<<" ";
}
cout<<i<<" ";
}
// In the above code loop executes 9 times ie. i=8 to i=0
hence the output :
8 7 6 5 4 3 2 1 0
after every number one space is printed as mentioned in the code.
case 5:
#include<iostream.h>
#include<conio.h>
void main()
{
for (int i = 2; i >= 0; i--)
{
cout<<"hello";
cout<<"abc";
}
}
{
cout<<"hello";
cout<<"abc";
}
}
// In the above code loop will execute 3 times and both the words "hello" and "abc" will be displayed as they are within a single braces, but with out any space or new line as no space character and no new line is there .
Output:
helloabchelloabchelloabc
case 6:
#include<iostream.h>
#include<conio.h>
for (int i = 2; i >= 0; i--)
{
cout<<"hello";
cout<<"abc";
cout<<endl;
}
{
cout<<"hello";
cout<<"abc";
cout<<endl;
}
// In the above code loop will execute 3 times and both the words "hello" and "abc" will be displayed.After helloabc there is a new line so output will be:
helloabc
helloabc
helloabc