跳转到基于条件的不同开关案例,如goto(Jump to a different switch case based on conditon, like a goto)

系统教程 行业动态 更新时间:2024-06-14 17:01:34
跳转到基于条件的不同开关案例,如goto(Jump to a different switch case based on conditon, like a goto)

我需要根据病情从一种病例转移到另一种病例。 例如,这是我的代码:

switch (req.method) { case 'GET': alert('GET METHOD'); break; case 'POST': alert('POST METHOD'); break; case 'PUT': alert('PUT METHOD'); break; default: res.end(); }

在上面的代码中,在POST情况下,我需要检查,例如, if(A === B) ,然后去像这样的PUT情况。 这个怎么做?

I need to move from one case to another case based on the condition. For example, this is my code:

switch (req.method) { case 'GET': alert('GET METHOD'); break; case 'POST': alert('POST METHOD'); break; case 'PUT': alert('PUT METHOD'); break; default: res.end(); }

In the above code, in the POST case I need to check, for example if(A === B), then go to the PUT case like that. How to do this?

最满意答案

进行条件递归

function checkMethod(method) { switch (method) { case 'GET': alert('GET METHOD'); break; case 'POST': alert('POST METHOD'); checkMethod('PUT'); // here stand the pros of a function break; case 'PUT': alert('PUT METHOD'); break; default: res.end(); } }

Make a conditional recursive

function checkMethod(method) { switch (method) { case 'GET': alert('GET METHOD'); break; case 'POST': alert('POST METHOD'); checkMethod('PUT'); // here stand the pros of a function break; case 'PUT': alert('PUT METHOD'); break; default: res.end(); } }

更多推荐

本文发布于:2023-04-20 18:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c2347a438a4528bf2fc0634efa199c5b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳转到   条件   案例   goto   Jump

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!