Properties box for the "While Loop" in version FC9

For general Flowcode discussion that does not belong in the other sections.
Post Reply
alanwms
Posts: 117
http://meble-kuchenne.info.pl
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 24 times
Been thanked: 7 times

Properties box for the "While Loop" in version FC9

Post 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.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: Properties box for the "While Loop" in version FC9

Post 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
Attachments
Loop Count Using Varaible.fcfx
(8.86 KiB) Downloaded 36 times
Martin

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: Properties box for the "While Loop" in version FC9

Post 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

alanwms
Posts: 117
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 24 times
Been thanked: 7 times

Re: Properties box for the "While Loop" in version FC9

Post 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.

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: Properties box for the "While Loop" in version FC9

Post by mnfisher »

You can of course use a variable...

A simple example -
Flowcode1.fcfx
(10.85 KiB) Downloaded 43 times
Martin

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Properties box for the "While Loop" in version FC9

Post 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

alanwms
Posts: 117
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 24 times
Been thanked: 7 times

Re: Properties box for the "While Loop" in version FC9

Post 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....

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: Properties box for the "While Loop" in version FC9

Post by mnfisher »

Using a variable lets you access the value of the count in the loop.

The demo prints this...

alanwms
Posts: 117
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 24 times
Been thanked: 7 times

Re: Properties box for the "While Loop" in version FC9

Post 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.

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: Properties box for the "While Loop" in version FC9

Post by mnfisher »

The FC 'hides' various type of C loops.

So for example doing a loop with count 10 variable 'i'
translates into

Code: Select all

for(i = 0; i < 10; i++) 
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

Code: Select all

while(expr){
}
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

Post Reply