Page 1 of 1
Properties box for the "While Loop" in version FC9
Posted: Wed Jan 25, 2023 9:56 pm
by alanwms
Hello -
I do understand how the while loop works. Predominantly used if for a specific count value.
I tried the "count using a variable" drop down box. That seems squirrely and does not do what I would inherently expect. However, selecting the "loop Count" check box and putting the variable name in the count dropdown box works.
Is the "count using a variable" drop box redundant? It doesn't seem to work.
Re: Properties box for the "While Loop" in version FC9
Posted: Wed Jan 25, 2023 10:16 pm
by medelec35
Hello.
I have attached a basic example.
It must be noted that no matter what the variable is initilised to, it will will automatically initialise to 0
Re: Properties box for the "While Loop" in version FC9
Posted: Thu Jan 26, 2023 9:24 am
by mnfisher
The setup allows several types of loop.
While
For example set expression .y < 10 then in the loop increment .y in a calculation block. Making the check at the end of the loop is a repeat until loop.
For loops - use a count for example 10 times. If you don't specify a variable FC creates one though you can't access it. If you need to index into an array - use count using a variable
For example loop 10 times using .i then arr[.i] =.i would set an array values to 0..9
Martin
Re: Properties box for the "While Loop" in version FC9
Posted: Sat Feb 25, 2023 3:38 pm
by alanwms
For the example where the count box is 20, and the "count using variable" is checked, and the variable is "count"
That does not make sense to me since simply using the number 20 in the count box performs the same function. The word "Count" in the variable is redundant. Am I missing someyhing?
What I would really like to do is put a variable in the count box, and have it count from that value. How do I achieve that?
Thanks.
Re: Properties box for the "While Loop" in version FC9
Posted: Sat Feb 25, 2023 4:04 pm
by mnfisher
You can of course use a variable...
A simple example -
Martin
Re: Properties box for the "While Loop" in version FC9
Posted: Sat Feb 25, 2023 10:02 pm
by WingNut
You can use the variable to alter the count value at various points in your program to change the value. If you only need a specific count then just change the count value in the macro but using a variable gives greater flexibility
Re: Properties box for the "While Loop" in version FC9
Posted: Sat Mar 04, 2023 12:47 am
by alanwms
Still confused - The example not only uses a variable, but it has a count in it also. Maybe there's a wiki explanation....
Re: Properties box for the "While Loop" in version FC9
Posted: Sat Mar 04, 2023 6:55 am
by mnfisher
Using a variable lets you access the value of the count in the loop.
The demo prints this...
Re: Properties box for the "While Loop" in version FC9
Posted: Sun Mar 05, 2023 3:55 pm
by alanwms
In my mind, simply putting a variable inside the "variable" box and not having it somehow automatically set to zero would be ideal. That would give me the flexibility without involving multiple variables to achieve the same thing. I view a variable as a number so there must be a reason that one can't put a preset variable in the box giving full variability to the count.
I see the operation of the example you provided but I'm confused about the complexity of not simply allowing a single variable operation.
Re: Properties box for the "While Loop" in version FC9
Posted: Sun Mar 05, 2023 4:29 pm
by mnfisher
The FC 'hides' various type of C loops.
So for example doing a loop with count 10 variable 'i'
translates into
If you specify a variable then you can access the value within the loop. If you don't then FC actually creates a (global) variable and uses this. (And in this case - the loop would execute with 'i' = 0,1,2 .. 9)
Similarly 'while' expression expands to
and while execute your code whilst the expression is true. (so something like 'i < 10').
Many times you'll see this
Code: Select all
i= 0
while(i <10) {
do something
i = i + 1
}
Loop until - expands to a do .. until(expr) loop
Martin