Jump to content

No "goto" so?


Recommended Posts

Ok... I read the FAQ and I saw that the command "goto" is not there anymore... I don't want to know why :)

But now I have a doubt (I don't think that the example on the FAQ can be applied here).

Let's say I need something like

$var = IniRead("C:\Temp\myfile.ini", "section2", "key", "0");var can be "0" or "1" or "2" or "3"

if $var=0 goto 1
if $var=1 goto 2
if $var=2 goto 3
if $var=3 goto 4

1
$var="sample1"
goto 5
2
$var="sample2"
goto 5
3
$var="sample3"
goto 5
4
$var="sample4"
5
exit

That is just an example, of course.... now... can anyone give me a clue how can I do that without the "goto(s)".

My objctive is to be able to merge different "scripts" in one... launching the "part" I want to after reading the variable from an INI file - FYI... I need to merge them 'cause they alway have the size of 173kb if seperated, and something tells me that if I merge I'll be able to have them all with a file size almos equal :mellow:

Thanks in advance

Link to comment
Share on other sites

maybe

$var = IniRead("C:\Temp\myfile.ini", "section2", "key", "0");var can be "0" or "1" or "2" or "3"

if $var=0 Then goto1()
if $var=1 Then goto2()
if $var=2 Then goto3()
if $var=3 Then goto4()

Func goto1()
$var="sample1"
goto5()
EndFunc

Func goto2()
$var="sample2"
goto5()
EndFunc

Func goto3()
$var="sample3"
goto5()
EndFunc

Func goto4()
$var="sample4"
goto5()
EndFunc

Func goto5()
exit
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Would While...WEnd or Select...Case...EndSelect do the job (refer Help file)?

(Don't forget the otherwise bit, where none of the valid clauses apply - often a gotcha that makes debugging and program flow a real pain)

Edited by Confuzzled
Link to comment
Share on other sites

If $var = 0 Then
;zeroth stuff
;...
ElseIf $var = 1 Then
;first stuff
;....
ElseIf $var = 2 Then
;second stuff
;....
ElseIf $var = 3 Then
;third stuff
Else
;optional other case
EndIf

Select...Case...EndSelect is also a good choice

Switch...Case...EndSwitch (in beta AutoIt version) is another

Switch $var
Case 0
;zero...
Case 1
;one...
Case 2
;two...
Case 3
;three...
EndSwitch

Edit: Well, the inner blocks should be indented. If you have really long sections of code, you could make the If statement or Case statement call a function like in Valuater's example.

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...