[SOLVED] Why does it say that i isn't equal to -1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[SOLVED] Why does it say that i isn't equal to -1?

Is someone able to explain this to me? int main() { string str; getline(cin,str); int x; x = str.size(); for (int i=x;i!=-1,i--;)

16th Feb 2020, 4:36 PM
Mr.FreshBoi
Mr.FreshBoi - avatar
4 Answers
+ 4
I think there's a mistake. The loop line should look like this: for(int i=x; i!=-1; i--) The middle part of the for loop determines the condition that keeps the loop running. So as soon as i becomes equal to -1, the loop is over. Was your finishing of the C++ tutorial a while ago? Maybe it is time for a review! In case I have simply misunderstood your question, please clarify. Also you might want to add a bit more of the code (the loop body for example), so that we get an idea what this is about. Also there are more tags you could use, for example 'C++', 'loops' or something else you find fitting for your question.
16th Feb 2020, 5:01 PM
HonFu
HonFu - avatar
+ 1
HonFu I think you're right It's time for a review 😂
16th Feb 2020, 5:19 PM
Mr.FreshBoi
Mr.FreshBoi - avatar
0
Aaahh I understand now thx dude
16th Feb 2020, 5:18 PM
Mr.FreshBoi
Mr.FreshBoi - avatar
0
Yeah that's my bad it was meant to be a semi colon
16th Feb 2020, 6:04 PM
Mr.FreshBoi
Mr.FreshBoi - avatar