Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring variable in FOR loop

Tags:

c++

loops

declare

I know in C++ that you can declare on variables inside the FOR, e.g:

for(int i=0; i<10; i++)

is there any way to declare another variables inside the for? this won't work for me:

for(int i=0, char Ch='J'; i<10; i++)
like image 469
Jjang Avatar asked Nov 28 '22 14:11

Jjang


1 Answers

You could use a std::pair:

for (std::pair<int, char> p(0, 'j'); p.first < 10; p.first++)
{
}
like image 189
hmjd Avatar answered Dec 18 '22 08:12

hmjd