How to exit if condition is met


#1

am trying to exit a script when the condition is met

(
if a==1
then
exit
)
else
(
a=1
)

i want to do something like this the first time it runs it skips to and evaluate the (else) lines
then the next run it will evaluate the ( then ) lines and exits without re-evaluating the (else) lines

is this even possible ?


#2

logically it’s the same as:

a = 0
if a != 1 do a = 1

#3

if you re-run the script the a value will be zero again
what am trying to do is to check if its = 1 if not then make it = 1
then when the script is re-run again it will remain 1 and will fall in the condition and exit without the need to evaluate the code under else again
i hope i could explain what am after


#4
a = 0
once_set = false

(
	if a != 1 do
	(
		if not once_set do
		(
			a = 1 
			once_set = true 
		)
	)
	if a == 1 do
	(
		-- ...........
	)
)

#5
(
	global a
	
	if a != 1 do
	(
		a = 1
		-- Evaluate your code here
		print "Hello World"
	)
)

From a function:

(
	global a
	
	fn EvaluateCode = if a != 1 do
	(
		a = 1
		-- Evaluate your code here
		print "Hello World"
	)
	
	EvaluateCode()
)

#6

thanks alot ,can you please explain what once_set is and whats its doing ?


#7

is their any benefit in doing it a function instead ?


#8

No, it’s just a matter of design or organization. It’s up to you to decide it.