Loops are the tools to make a instruction execute depends on how many times we want.
we all of us know loops in c++ are of three types :
- For loop
- while loop
- do while loop
syntax of for loop is simple :
for(initialisation statement ; test condition ; update statement)
{
... set of statements ;
}
OK , now you are clear here yet .
my question is what is the output of the following code :
string var = "aayush";
for(char c : var)
{
cout << c << " ";
}
output is :
a a y u s h
that's here is the concept of range based for loop.
when for loop terminates corresponding to some type of list like array , string , vector with only a single condition as loop argument , then this type of for loop is called range based for loop.
According to c++ refrenece :
Executes a for loop over a range.
Used as a more readable equivalent to the traditional for loop operating over a range of values, such as all elements in a container.
syntax :
Comments
Post a Comment