What's Arrow Operator ??
Actually, arrow operator is used to tend down from any higher value to the lower value using the while loop in the programs.
---------------------------------------------------------------------------------------------------------
* Used for tending down any higher value to lower value*
---------------------------------------------------------------------------------------------------------
Lets say, we have the value of 'i=10'. and we want to move towards '0' by printing all these values of the variable 'i'.
Then, we can simply apply the 'arrow operator(-->)' in the while loop without using any decremental statement like 'i--' in the while loop for the variable 'i'.
So the Simple code for this example would be :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ clrscr();
int i=10;
cout<<"Tending Down Value of Variable i is \n";
while(i-->) // Arrow Operator ( --> )
{
cout<<i<<"\n";
}
system("pause");
}
So, the output of the code will be :
Tending Down Value of Variable 'i' is
10
9
8
7
6
5
4
3
2
1
0
press any key to continue
--------------------------------------------------------------------------------------------------------
*It reduces the use of decremental statements in the loop*
--------------------------------------------------------------------------------------------------------
So, By using the 'arrow operator', we can get rid of the decremental statements in the while loop.
Here, this task could also be performed simply using the statements as :
while(i>0)
{
i--; // decremental statement ( i-- )
cout<<i<<"\n";
But , the 'arrow operator' makes this conditional useless.
So, By using the 'arrow operator', we can get rid of the decremental statements in the while loop.
Here, this task could also be performed simply using the statements as :
while(i>0)
{
i--; // decremental statement ( i-- )
cout<<i<<"\n";
}
But , the 'arrow operator' makes this conditional useless.

No comments:
Post a Comment