If loop and array in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If loop and array in C++

Can I use if loops in arrays like this:- string test="Yes"; string test1="No"; if(test=test1){ cout<<test; } else{ cout<<test1; }

10th Jul 2020, 10:14 PM
Joocaar Jucfe
5 Answers
+ 11
Your code will give error but in if condition u cannot assign value .
11th Jul 2020, 6:30 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
A if-condition / -branch is never any kind of a loop. This piece of code can be used within a loop. And please note, that your if-condition will always remain true and your else-branch is dead code.
10th Jul 2020, 10:49 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
That's interesting 🤔 Tested with android app, Samsung browser in mobile mode, Samsung browser in desktop mode, Chrome: I see 6 messages, 3 from you, 2 from me, 1 from Sandra Meyer
11th Jul 2020, 6:20 PM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
In original code, as Sandra Meyer pointed out, else-branch is dead code. In code corrected by Martin Taylor, if-branch is dead code. What are you trying to do?
11th Jul 2020, 4:37 AM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
Martin Taylor Are you joking? She gave the first answer, 15 hours ago
11th Jul 2020, 2:01 PM
Bilbo Baggins
Bilbo Baggins - avatar