Is this a valid statement?If valid, plzz explain how the loop will execute? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Is this a valid statement?If valid, plzz explain how the loop will execute?

while (a<4,i>10)

21st May 2020, 3:10 PM
Sayed Ayaan
Sayed Ayaan - avatar
6 Answers
+ 1
What programming language is it? And what should it do?
21st May 2020, 3:34 PM
Lisa
Lisa - avatar
+ 1
I do not know c++ but I suppose conditions should be joined by logical operators, not by comma
21st May 2020, 3:57 PM
Lisa
Lisa - avatar
+ 1
you could put many statements comma separated, but only the result of the last (right most) statement will be used to evaluate the condition result (in your example, the while loop will break only if i<=10, the first statement will not have effect on the loop condition)
21st May 2020, 4:45 PM
visph
visph - avatar
0
If you are considering Python, it is indeed a valid loop. However, it is an infinite loop, because the condition will always be True, regardless the values of a and i. This is because you put a tuple as argument and it always returns True unless it's empty. Since it is never empty, the loop will run forever. Consider changing the comma to a logical operator, like "and" or "or". Then see what happens :)
21st May 2020, 3:37 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Lisa it is c++ I am just asking that can we put the conditions like that (separated by commas)
21st May 2020, 3:53 PM
Sayed Ayaan
Sayed Ayaan - avatar
0
visph thanks
21st May 2020, 4:55 PM
Sayed Ayaan
Sayed Ayaan - avatar