根据while循环内的互动响应,在R中停止while循环(在另一个while循环内)

时间:2018-07-25 17:39:44

标签: r while-loop command-prompt interactive

我希望根据提示回答以交互方式停止和退出R中的while循环(在另一个while循环内),但继续进行外部循环。

请参见下面的代码:

outside_loop_flag  = TRUE
inside_loop_flag   = TRUE

outside_loop_index = 1
inside_loop_index  = 1

while ( outside_loop_flag == TRUE )
{


  while ( inside_loop_flag == TRUE )
  {
   ### I do something here

   ### IMPORTANT: I want to put a condition here like:
   ### check = readline("Wanna go on still?")
   ### if (check == "no") then get out of the inside loop
   ### even if inside_loop_index < 10^3 but still execute 
   ### the outside loop.

   inside_loop_index = inside_loop_index + 1
   if ( inside_loop_index > 10^4 ) inside_loop_flag = FALSE
}


  outside_loop_index = outside_loop_index + 1

  if ( outside_loop_index > 10^4 ) outside_loop_flag = FALSE

}

0 个答案:

没有答案