How can I add more variables to a for loop in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I add more variables to a for loop in C++?

I tried to add more variables to a for loop by this: for(int a = 10, b = 11; a != 0; a--, b++) { ... } When i try to run it my compiler says, 'error: unqualified-id before 'int' '

28th Jun 2017, 1:01 PM
Harm Meyer-Borstel
Harm Meyer-Borstel - avatar
5 Answers
+ 8
I just copied your text and it worked just fine, I think the error is somewhere else: https://code.sololearn.com/cis8zLKFwwG3/?ref=app
28th Jun 2017, 1:50 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 6
computer says no
28th Jun 2017, 1:06 PM
jay
jay - avatar
+ 6
It works fine for me. #include <iostream> using namespace std; int main() { for (int a = 0, b = 3; a < b; a++, b--) { cout << a; } return 0; } It says 01 as I expected..
28th Jun 2017, 1:08 PM
김정제(Legacy)
김정제(Legacy) - avatar
+ 6
I don't have a desktop at the moment, but I do remember encountering the same errors when trying to declare more than one variable in a for loop. Code Playground, however, does not reflect this error. I will check on this when I have time.
28th Jun 2017, 2:08 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
I found my error and i made a error in the question. Sorry. I don't write the code that i wrote in the question. I write two times int for(int a=10, int b=11... Now it works for me fine Thank you all for your ideas
28th Jun 2017, 2:20 PM
Harm Meyer-Borstel
Harm Meyer-Borstel - avatar