Im doing a homework problem to make a function sumOdd to computer the sum of the first n odd integers, but i cant seem to find any sort of elseif type statement to do so. What im trying to do is below but of course doesnt work:
fun sumOdd n = if n=0 then 0 elseif (n mod 2)=0 then sumOdd(n-1) elseif n + sumOdd(n-1);
Your function didn’t compile because
elseifis not a keyword in SML. Changing the lastelseiftoelseand otherelseiftoelse ifshould fix the error.Furthermore, the function is more readable in the below format: