NochnoiDozor Posted October 8, 2006 Share Posted October 8, 2006 Forgive the simplicity of teh question, but I have code with a lot of nested if statements if... ...endif if... ...endif if... ...endif and so on However, when the first 'if' is fulfilled, it doesn't continue to do the rest. How can I code it to complete all if statements after the first one? btw, I have tried using 'elseif' statements, but still the same problem Link to comment Share on other sites More sharing options...
Helge Posted October 8, 2006 Share Posted October 8, 2006 Please show some actual example code which you have problems with. Link to comment Share on other sites More sharing options...
NochnoiDozor Posted October 8, 2006 Author Share Posted October 8, 2006 If $number = $counter Then Send("hello1") sentIt() adding() ElseIf $number = $counter then Send("hello2") sentIt() adding() ElseIf $number = $counter then send("hello3") sentIt() adding() and so on (btw, counter and number are both incrememnted in sentIt() So, is, say, number and counter are both 1, the first if statement to send hello1 is done, but it doesn't do the rest, even though number and counter are both incremented and the 2nd if statement is true. Link to comment Share on other sites More sharing options...
Cue Posted October 8, 2006 Share Posted October 8, 2006 (edited) HI because youve used elseif use endif. but in your first post you have it written right!! Edited October 8, 2006 by Cue Link to comment Share on other sites More sharing options...
NochnoiDozor Posted October 8, 2006 Author Share Posted October 8, 2006 But in my first post, if I use that code it only ever does one if statement, but I want it to do them all Link to comment Share on other sites More sharing options...
sulfurious Posted October 8, 2006 Share Posted October 8, 2006 If's are easy to understand once you learn to follow the 'nest'. If you have not, use SciTe or equivilent to create a script in. Now, just make a bunch of If EndIf. Nested inside one another, something like this If If If Else EndIf Else If Else EndIf EndIf Else If If Else EndIf Else If Else EndIf EndIf EndIf SciTe will let you 'fold' the script up with the + or - box on the left. You will quickly note that every If needs an EndIf, and that SciTe will visually show you where you are missing them. You can then 'fold' them up, and then start to follow them out, one 'fold' at a time on each branch until you see where an action is performed. Depending upon where the action is, the parent if may end, or it may follow a prior If. It found it much easier using an IDE for those things, especially one like Scite that lets you fold. Just my 2cents tho. Sul Link to comment Share on other sites More sharing options...
Helge Posted October 8, 2006 Share Posted October 8, 2006 But in my first post, if I use that code it only ever does one if statement, but I want it to do them allEehm, that's not true. If you build up your code like that you will get exactly what you want,while if you do like on your second post it will only execute the statements for the first trueexpression. Link to comment Share on other sites More sharing options...
tresa Posted October 8, 2006 Share Posted October 8, 2006 (edited) THe best is to add a new function I name result and in the main code call it The $number and $counter will be changed by each call with sentIt (if $number=$counter) The code will be a lot clearer func result($strResult) If $number = $counter Then Send($strResult) sentIt() adding() endif endfunc result("Hello1") result("Hello2") result("Hello3") result("Hello4") Edited October 8, 2006 by tresa Link to comment Share on other sites More sharing options...
NochnoiDozor Posted October 8, 2006 Author Share Posted October 8, 2006 (edited) EDIT: Fixed it! All is working well - thanks guys. Edited October 8, 2006 by NochnoiDozor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now