In: Computer Science
NOTE:If you are stuck somewhere feel free to ask in the comments but do not give negative rating to the question as it affects my answering rights.....I will try to help you out
ans=True
It is definately an infinite loop since the initial value of flag is equal to false,
Now the condition in the while loop states that is the flag is not true which means if flag=false then, iterate
Now some may say that the syntax is wrong since you have a semicolon after the condition in while loop.
When it is not the case we can use such syntax which simply means we dont have the body of the while loop but iterate till the condition becomes false
I know kind of weird but true. It makes no sense to use while loop when there is no body of the loop .But that is what we have in c++
Hence it will iterate till flag becomes true which is never hence infinite iterations.
Also you may think that
{
cin >> num;
if(num == -1) {
flag = true;
} THIS SURELY CORRESPONDS TO THE BODY OF THE LOOP. IT IS NOT!!!
IT IS JUST A BLOCK OF SCOPE SINCE WE ALREADY CONCLUDED THE WHILE LOOP BY PUTTING A SEMICOLON