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.
Properties box for the "While Loop" in version FC9
-
- Posts: 117
- http://meble-kuchenne.info.pl
- Joined: Fri Dec 04, 2020 2:29 pm
- Has thanked: 24 times
- Been thanked: 7 times
-
- Matrix Staff
- Posts: 1560
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 555 times
- Been thanked: 514 times
Re: Properties box for the "While Loop" in version FC9
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
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 130 times
Martin
-
- Valued Contributor
- Posts: 1133
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 114 times
- Been thanked: 596 times
Re: Properties box for the "While Loop" in version FC9
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
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
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.
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
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
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.
I see the operation of the example you provided but I'm confused about the complexity of not simply allowing a single variable operation.
-
- Valued Contributor
- Posts: 1133
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 114 times
- Been thanked: 596 times
Re: Properties box for the "While Loop" in version FC9
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
Loop until - expands to a do .. until(expr) loop
Martin
So for example doing a loop with count 10 variable 'i'
translates into
Code: Select all
for(i = 0; i < 10; i++)
Similarly 'while' expression expands to
Code: Select all
while(expr){
}
Many times you'll see this
Code: Select all
i= 0
while(i <10) {
do something
i = i + 1
}
Martin