1

How can multiple conditions be specified under single if? For example, consider the following java code snippet:

if(a==1 && a>b){
    //statements ;
}

How can above code be written in sml? I know that I can achieve the goal by using two if's but still if there is a method to specify in the way I want, then it will be smooth.

1
  • Warning: there is no == in SML. There is a == in OCaml that you should not use. Commented Jan 30, 2016 at 20:35

1 Answer 1

5

SML's equivalent of && is andalso. For || there is orelse:

if a = 1 andalso a > b
then (* ... *)
else (* ... *)
Sign up to request clarification or add additional context in comments.

2 Comments

@lonut G. Stan Do we always need to add 'else'?
@AnkitShubham SML's philosophy is strongly against overloading. and is used for defining mutually recursive functions hence not available for use as a logical operator. andalso was chosen by the developers instead. My guess is that it was felt to be too stylistically jarring to have andalso paired simply with or, so orelse what chosen instead, even though or by itself isn't used for anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.