skulpt / skulpt

Skulpt is a Javascript implementation of the Python programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to end the while loop internally?

oicoderr opened this issue · comments

How to end the while loop internally?
example:
a = int(input())
print(a)
while a < 5:
b=input(':')
print(b)
a+=1

这是一个例子:https :
//jsfiddle.net/sc549/bjLuq5s7/

If you use textArea as input, it cannot be terminated.
example:
inputfun: function(args) {
return new Promise(function(resolve, reject) {
$('#Textarea').on('keyup', function(e) {
if (e.keyCode == 13) {
resolve($('#outputTextarea').val())
}
})
})}

commented

If you can reject the input promise then you can kill the execution.

Something like the following.

inputfun: function(args) {
  return new Promise(function(resolve, reject) {
    $('#Textarea').on('keyup', function(e) {
      if (e.keyCode == 13) {
        e.preventDefault();
        resolve($('#Textarea').val())
      }
    })
    $('#stopBtn').on('click', () => reject(new Sk.builtin.SystemExit('Execution interrupted')));
  })
}

It might be worth removing those event listeners on those elements once the Promise has resolved/rejected.

如果您可以拒绝输入承诺,那么您可以终止执行。

类似于以下内容。

inputfun: function ( args )  { 
  return  new  Promise ( function ( resolve ,  reject )  { 
    $ ( '#Textarea' ) . on ( 'keyup' ,  function ( e )  { 
      if  ( e . keyCode  ==  13 )  { 
        e . preventDefault ( ) ;
        解析( $ ( '#Textarea' ) 。val ( ) ) 
      } 
    } ) 
    $ ( '#stopBtn' ) 。上('点击'  () => 拒绝(新 Sk的。内置。SystemExit '执行中断' ))); 
  } ) 
}

一旦 Promise 已解决/拒绝,可能值得删除这些元素上的事件侦听器。

Oh yer great, thanks