Yep.EDIT: How do you know which "case" corresponds to which "condition" in the example I gave? Is it as simple as: case 1 = condition 1?
tidying up code - tips?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: tidying up code - tips?
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: tidying up code - tips?
Cool, but let's assume I have multiple "end / ifs" as Klaus was alluding to earlier.
For instance:
In this example, it's much more nested. Anyway to use the case / switch stuff on a scenario like this?
For instance:
Code: Select all
if condition = 1then
if item 1 of line x of data = "test" then
if item 7 of line x of data = 1 then
#STUFF
else if item 7 of line x of data = 3 then
# STUFF
end if
else if item 1 of line x of data = "XYZ" then
#Stuff
end if
else if condition = 2 then
if item 1 of line x of data = "test" then
if item 7 of line x of data = 1 then
....
Re: tidying up code - tips?
Here's my take on that. Note that switch statements can be nested and that you can mix switch statements with embedded if/then/else statements as well. And also that you haven't defined any default catch-all cases (I put one in for you as an example).
Code: Select all
switch condition
case 1
switch item 1 of line x of data
case "test"
switch item 7 of line x of data
case 1
#STUFF
break
case 3
# STUFF
break
end switch -- item 7 of line x of data
case "XYZ"
#Stuff
break
default
-- do stuff here to catch item 1 not being "test" or "XYZ"
break
end switch -- item 1 of line x of data
case 2
switch item 1 of line x of data
case "test"
switch item 7 of line x of data
....
end switch -- item 1 of line x of data
end switch -- condition
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: tidying up code - tips?
I successfully used this trick, and it helps out immensely by making the code much more readable. Thank you!!
Re: tidying up code - tips?
Glad it helped. I tend to use switch statements a lot, but there are also some situations where if/then/else statements make things more clear. An example might be long switch statements where you have to switch back and forth a lot to try to figure out the program flow to see what's connected to what and what level of indentation you're looking at.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: tidying up code - tips?
I noticed you have some software in your personal signature related to debugging. Could you talk about that a bit? I'm interested in more efficient and comprehensive debugging methods, and perhaps your software can help me with that?
Thank you.
Thank you.