0

function between two numbers

hi everyone

i have the following issue... 

I need to show a message following numeric rules.

for example..

if number < 5 then "Result 1"

if number > 10 then "result 3"

but now, how I force "result 2" between 5.1 and 9.9... 

I tried if number >5 and <10 then "result 2"

but is not working

thanks in advance

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Alex Mumm
    • Alex_Mumm
    • 6 mths ago
    • Reported - view

    You probably need nested If statements:

    if Number < 5 then
        "Result 1"
    else
        if Number > 10 then
            "Result 3"
        else
            "Result 2"
        end
    end
    

    First it checks if the number is less than 5, if it isn't then it checks if it's greater than 10, if it isn't then it must be between the two numbers (result 2).

    Like
    • Alex Mumm thanks for your quick response

      but what if I need 4 results... like >5, 5 to 7.5, 7.6 to 10 and >10.

      thanks!

      Like
      • Lars
      • Lars
      • 6 mths ago
      • Reported - view

      Cirugia Toracica what about the following:

      "-- these are the results from highest to lowest --"
      let results := [3, 2, 1];
      "-- these are the upper boundaries for any result --"
      let boundaries := [10, 7.5, 5];
      
      "-- initialise the result with the highest possible value --"
      let result := 4;
      
      "-- go down from boundary to boundary and check --"
      for i from 0 to 3 do
         if myValue < item(boundaries, i) then result := item(results, i) end;
      end;
      

      You can always extend the results in the array to whatever maximum value you like, you don't even need to have a sequence of numbers, you can assign any result you like.

      If you extend the number of results, you also have to extend the number of boundaries. Any value is possible, as long as they are in descending order. 

      The initialisation can also be with any value you like.

      Finally you have to adapt the for-loop to the number of results. I. e. if you have 6 results, the results array will have five entries and you have "for i from 0 to 5".

      You can also create a function for that:

      function rating(n : number) do
          let results := [3, 2, 1];
          let boundaries := [10, 7.5, 5];
          let result := 4;
          for i from 0 to 3 do
             if n < item(boundaries, i) then result := item(results, i) end;
          end;
          result;
      end;
      
      rating(8.8)
      
      

      The advantage is, that the number of ifs and switches etc. gets not larger if you have more cases to differentiate. You just adapt some numbers

      Like
    • Fred
    • Fred
    • 6 mths ago
    • Reported - view

    You can use a switch function. It is not intuitive but you can do something like:

    switch true do
    case number < 5:
    "result 1"
    case number >= 5 and number < 7.5:
    "result 2"
    case number >= 7.5 and number <= 10:
    "result 3"
    case number > 10
    "result 4"
    end
    

    number is a field name.

    Like
    • Fred
    • Fred
    • 6 mths ago
    • Reported - view

    If you take a look at this post, you will see that you can use arrays in the switch function.

    Like
Like Follow
  • Status Answered
  • 6 mths agoLast active
  • 5Replies
  • 67Views
  • 4 Following