Skip to main content
12-Amethyst
Solved

If loop with a range variable

Hi

 

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

 

12-Amethyst

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

11 replies

Werner_E
25-Diamond I

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.

 

 

Translate
12-Amethyst

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

Translate
Werner_E
25-Diamond I

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

 

Translate