question

SudheerReddy avatar image
0 Likes"
SudheerReddy asked Allister Wilson edited

Please explain while loop which has test condition as treenode

FlexSim 19.1.2
loop
doubt.png (52.1 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Allister Wilson edited

The condition isn't NULL as long as the variable item gets a value to a next item. If the loop has set the label tally to 0 for all items on the conveyor, the next item after the last one will get the reference NULL. Then the loop is ending.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

SudheerReddy avatar image SudheerReddy commented ·

Usually while loop will work for true or false conditions. If true execute the code or false skip the code. Here variable item which returns a path reference for while(item) condition, then how the while loop will run. Is that considered to be true. If it is considered to be true then why it is considered to be true.Is Null is considered to be false.

0 Likes 0 ·
Allister Wilson avatar image Allister Wilson SudheerReddy commented ·

Flexscript follows similar rules to C and C++ when it comes to implicit boolean conversions. A treenode behaves like a pointer in this context.

https://en.cppreference.com/w/cpp/language/implicit_conversion

2 Likes 2 ·
Joerg Vogel avatar image Joerg Vogel SudheerReddy commented ·

Yepp, that is how it works. As long as it works , what does it matter that something is true and nothing is false.

0 Likes 0 ·