-2

I have difficulty understanding this while loop:

enter image description here

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • what is the question? – Andrew Dec 12 '22 at 15:58
  • I have attached the code in the Image. e – Karan Soni Dec 12 '22 at 16:02
  • set mode [pw::Application begin ExtrusionSolver $block] set result Completed while {1 == [string equal $result Completed]} { $mode run set result [lindex [$mode getRunResult] 0] switch $result { Error - SolverFailure { puts "Extrusion solver encountered an error" } Completed - StopCriteria { } } } $mode end } – Karan Soni Dec 12 '22 at 16:02
  • @KaranSoni it would be helpful if you could explain what about this loop you don't understand. – glenn jackman Dec 12 '22 at 16:44

1 Answers1

1

The Condition

The condition:

while {1 == [string equal $result Completed]} {

could be written more shortly as:

while {$result eq "Completed"} {

That is, it means "do the body while $result is equal to the literal string Completed.

The Body

The body of the loop calls $mode run (what exactly that does isn't described here). Then it gets the result by calling $mode getRunResult and extracts the first word of the list, and assigns it to the variable result. The final step of the loop is to use switch to print a message whenever $result is either Error or SolverFailure (it also has clauses for Completed and StopCritera, but that's empty so nothing happens).

The Overall Effect

The loop calls $mode run until the first word of the result of $mode getRunResult after that run is not Completed.

$mode is a handle returned by pw::Application begin ExtrusionSolver $block, and $mode end is called after the loop terminates, presumably to clean things up.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • The setting of `result` to `Completed` before the loop just means that we're going to definitely run the loop body at least once. – Donal Fellows Dec 12 '22 at 16:35