Standard ML multiple condition statement

喜夏-厌秋 提交于 2019-12-14 03:21:51

问题


I am about finished with a script I am writing but I have one last condition statement to add to my function.

fun whileloop (x:real,a:int,b:real) =
    if (a<1)
    then (x,a,b) 
    else whileloop(x+1.0,a-1,b-1.0)

This is my current loop I have created. It is basically accomplishing everything I need under one exception. I want it to exit its loop once the b variable hits zero[if this happens before a reaches zero). I believe Standard ML will not let me do a condition statement for a real variable...such as b<1.0. just to give you an idea of what I am trying to accomplish...I want the following code to work below:

fun whileloop (x:real,a:int,b:real) =
    if (a<1 or b<1.0)
    then (x,a,b) 
    else whileloop(x+1.0,a-1,b-1.0)

of course this code does not work due to the syntax and a condition statement being checked against a real number...but how could I accomplish this task while keeping my skeleton somewhat intact. I simply want to add another if condition statement to the existing skeleton. In C++ this was a fairly simple task.


回答1:


Here is the answer. Thanks to John Coleman.

fun whileloop (x:real,a:int,b:real) =
    if (a<1 orelse b<1.0)
    then (x,a,b) 
    else whileloop(x+1.0,a-1,b-1.0)


来源:https://stackoverflow.com/questions/44489424/standard-ml-multiple-condition-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!