|
-
Jul 18th, 2005, 12:29 AM
#1
how can I break out of an if statement?
?????
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 18th, 2005, 12:54 AM
#2
Re: how can I break out of an if statement?
There is no breaking out of an If statement. You simply put the remainder of the code within that If into another, nested If statement. You would have to test some condition to know whether to break out anyway, and how would you do that if not with an If statement.
-
Jul 18th, 2005, 12:58 AM
#3
-
Jul 18th, 2005, 01:08 AM
#4
Re: how can I break out of an if statement?
Break is for loops or Switch only. Generally speaking you would test a condition to determine whether to break out of a loop, which means that the Break statement would be inside an If statement. It wouldn't be much help if break just exited the If.
-
Jul 18th, 2005, 01:10 AM
#5
Re: how can I break out of an if statement?
Actually, there is a way that I just thought of. You'll like this. It's goto, which is supported by C# as well VB.NET.
Edit:
And C++, and presumably C (edit: which I just confirmed by checking the index of my C text book from university, after blowing the dust off).
Last edited by jmcilhinney; Jul 18th, 2005 at 01:13 AM.
-
Jul 18th, 2005, 01:40 AM
#6
Re: how can I break out of an if statement?
hehe yeah I thought of goto
but don't you think it'd be a bad idea? Everyone considers it "evil" I've always heard I shouldn't use goto statements eh
that's the only solution apparently
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 18th, 2005, 01:42 AM
#7
Re: how can I break out of an if statement?
Only its misuse is evil. Tends to cause speghetti code if you have 25 of them in a 200 line program.
-
Jul 18th, 2005, 01:46 AM
#8
Re: how can I break out of an if statement?
The goto statement is considered "evil" because people abused it. It was included in programming languages in the first place for a reason, but undisciplined programmers used it wherever they felt like it instead of looking for the best solution. While I get an uneasy feeling myself saying this, if goto is used in only isolated situations then there is no potential for spaghetti code, which is the reason that goto got a bad name. As long as you use other solutions in situations where they are more appropriate, the occasional goto is not a mortal sin.
-
Jul 18th, 2005, 01:46 AM
#9
Re: how can I break out of an if statement?
Break out of an If statment is just as evil or not evil as using a Goto. It is unlogical, and breakes the normal flow of the app. Nothing more or less then that....
-
Jul 18th, 2005, 01:52 AM
#10
Re: how can I break out of an if statement?
I haven't tested this but it just occurred to me that the goto statement might be the answer to one of your earlier threads regarding falling through cases in a switch statement. That is more likely to be considered an abuse of goto than this current application though.
-
Jul 18th, 2005, 02:34 AM
#11
Re: how can I break out of an if statement?
 Originally Posted by jmcilhinney
The goto statement is considered "evil" because people abused it. It was included in programming languages in the first place for a reason, but undisciplined programmers used it wherever they felt like it instead of looking for the best solution. While I get an uneasy feeling myself saying this, if goto is used in only isolated situations then there is no potential for spaghetti code, which is the reason that goto got a bad name. As long as you use other solutions in situations where they are more appropriate, the occasional goto is not a mortal sin.
aha good explanation
I think I'll use goto for now
I was trying to break out of it instead of creating a new if block because the if block indents the code and I alreayd have too much indentations (I have too many loops and if statements inside another). I guess the real answer is that I should break my function down into smaller functions to make it simpler
thanks for all the replies
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 18th, 2005, 06:20 AM
#12
Re: how can I break out of an if statement?
 Originally Posted by MrPolite
I guess the real answer is that I should break my function down into smaller functions to make it simpler 
I was actualy just going to suggest that when I saw you did it your self. If you have so much logical branching that you have no room for more indentation, then it is definitly time to break up the function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|