Implement remaining command_... functions for control structures

master
BodgeMaster 2022-11-06 06:18:07 +01:00
parent f9f454625b
commit fbdf2e42f2
1 changed files with 16 additions and 0 deletions

View File

@ -173,12 +173,28 @@ def command_take():
return ""
def command_repeat(number, parsed_code):
for i in range(number):
result = run_code(parsed_code)
if not result=="":
return result
return ""
def command_while(parsed_condition, parsed_code):
while parsed_condition[0](parsed_condition[1]):
result = run_code(parsed_code)
if not result=="":
return result
return ""
def command_if(parsed_condition, parsed_then_code, parsed_else_code):
if parsed_condition[0](parsed_condition[1]):
result = run_code(parsed_then_code)
if not result=="":
return result
elif not parsed_else_code==None:
result = run_code(parsed_else_code)
if not result=="":
return result
return ""