Skip to main content
12-Amethyst
September 25, 2023
Solved

If loop with a range variable

  • September 25, 2023
  • 1 reply
  • 3483 views

Hi

 

How do I program an if-loop with a range variable, and not a scalar? Is that possible?

 

Best answer by ksk_10594232

I found a solution to get around the problem. Thanks anyways!

1 reply

25-Diamond I
September 25, 2023

The "if" statement is a branch, not a loop!

Its unclear to me what you mean and how this would have to do with a range variable.

Maybe you can give a couple of examples of what you are looking for.

 

If you are looking for multiple branching like the "switch" statement in C - Prime does not provide a comparable statement.

But depending on the specific problem its often possible to find a simpler solution compared to a cascade of if's and elseif's.

 

 

12-Amethyst
September 25, 2023

I have attached an example which I hope will clearify my question 🙂

25-Diamond I
September 25, 2023

And what kind of data structure do you expect as the output?

 

You have to be aware that ranges are not vectors! Ranges should only be used on three occasions:

To index the elements of a vector or matrix
In a for-loop inside a program
As abscissa values when you plot a function

 

In all other cases you should use vectors.

 

Maybe this is what you are looking for:

Werner_E_1-1695651361000.png

 

Prime 9 file attached