I have made a sample code in c.

do
{


 switch(i)
 {

 case 1:
 {
   cout<< "1\n";
   break;

 }
 case 2:
 {
      cout<< "1\n";
      break;
  }
  case 3:
  {
    continue;
  }


 }
 }while (0);

Here in this code if value of i is 3 then i want to restart the do while loop which will result in an infinite loop. But unfortunately loop is not getting executed again. What will be the reason for that.? I have checked the assembly code in visual studio of the same code and found that there is no JMP statement in the assembly for continue statement inside switch -case .

有帮助吗?

解决方案

while (0) means it will fall out the bottom of the loop. Even if you have continue the condition is re-eval'd

其他提示

When you do continue inside a do-while loop, it jumps at the evaluation at the bottom, that is always false in your case.

The other answers are explaining continue but it looks from your comments like you understand how that works.

if value of i is 3 then i want to restart the do while loop which will result in an infinite loop

The code is functioning as you describe - it is jumping to the 'while' condition on i==3. The only difference is that if you want an infinite loop you need while(1) not while(0).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top