问题描述
我即将完成我正在编写的脚本,但我有一个最后一个条件语句要添加到我的函数中。
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)
这是我创建的当前循环。它基本上是在一个例外情况下完成我需要的一切。我想让它在b变量达到零时退出它的循环[如果在达到零之前发生这种情况)。我相信标准ML不会让我为实变量做一个条件陈述......比如b
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)
当然这个代码由于语法不起作用并且根据实数检查条件语句......但是如何在保持骨骼完整的同时完成此任务。我只想在现有骨架上添加另一个if条件语句。在C ++中,这是一个相当简单的任务。
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.
推荐答案
这是答案。感谢John Coleman。
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)
这篇关于标准ML多条件声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!