This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Curious about the operation of this script
#1
Hello I have this sample script for the definition and call of functions.

Code:
function max(numero1, numero2)     
   if (numero1 > numero2) then     
      resultado = numero1;        
   else                            
      resultado = numero2;        
   end                            

   return resultado;             --
end

log('El valor máximo de la comparación de dos valores es',max(4,10))
log('El valor máximo de la comparación de dos valores es',max(6,5))
It works perfectly regardless of the order of the numbers passed to the function, it always returns the largest.
I have this other variation.
Code:
max = 4, 10
log('El valor máximo de la comparación de dos valores es', max)

function max(numero1, numero2)     

   if (numero1 > numero2) then     
      resultado = numero1;        
   else
      resultado = numero2;
   end
  return(resultado)
end

Here the problem is that if I change the order of the numbers, the function does not return the highest, it seems that it always returns the first.
What could this be due to? Is the way to call the function and pass it the arguments wrong?
a greeting
Reply


Messages In This Thread
Curious about the operation of this script - by JRP - 07.08.2020, 12:01

Forum Jump: