问题
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