GoTo command

Hello,

 Occasionally I wish Igor had a GoTo-like command for unconditional jumps. This command would bypass the need for conditional statements which incorporate large amounts of codes.

Thank you for your consideration.

Best,

Sebastian 

chozo

This sound to me as if it would be useful for you to move the code inside the condition into a separate function, which then can be called. I would argue this is a 'goto' command (to the function in question). If you want to let the function decide whether to skip the following code, you could do something like this:

function mainFunc()
	...
	if (subFunc())
		return 1
	endif
	... // may be skipped
end

function subFunc()
	...
	if (condition == 1)
		return 1 // skip
	endif
	return 0 // don't skip
end
aclight

I think the general opinion about the goto keyword is that it is a bad idea and leads to spaghetti code. See https://blogs.fahid.dev/goto-statements-and-why-to-avoid-it for example.

The most common use of goto I have seen is for cleanup/error handling, and you can usually use Igor's try...catch...endtry flow control to get the same end result. The other commonly used alternative is

do
     // this always executes exactly once
while(0)

You can use break from within do...while to jump to the code below the while keyword, which is similar to using something like goto error.

Otherwise, calling functions like chozo recommends is likely the best approach, since that usually makes your code easier to read, test, and maintain.

thomas_braun

While I do agree that goto is a bad command which should not exist, it would solve the cleanup/error handling difficulties. Using try/catch does not work as it breaks aborting from called code and do/while technically works but looks horrible. In C++ this is solved with RAII, and well in C with goto.