![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: continue Topic Summary: How does the continue statement work? Created On: 12-Oct-2006 14:16 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: It's the loop's next test statement. That's whatever is in the while/for/do or whatever that controls execution of the loop, not what happens inside the loop. 'break' and 'continue' treat the whole loop as a single thing, regardless of what's inside: for ... in ... do { // stuff if (...) continue // more stuff if (...) break // other stuff } In the snippet above, in each pass through the loop 'stuff' always get's done. 'more stuff' only gets done if the first 'if' evaluates false, and 'other stuff' only gets done if the second 'if' evaluates false. If the first 'if' evaluates true, the loop starts again from the top, with the next value from the 'for'. If the second 'if' evaluates true, the whole loop stops. I'm sure it can be said more succinctly (and no doubt someone will...), but maybe that will help for a starter. Taking another quick look at your post, the answer to the two questions are 'yes, it jumps to the top of the loop' and 'no, because it won't get as far as your 2nd if statement'. Paul. | |
![]() |
|
I am using a for loop with the entire option, and it includes the soft deleted items, which I don't want.
I was told to use the continue statement to skip over them. It works, but I really don't see how. The help file says "The continue statement effects an immediate jump to the loop's next test or increment statement. " In my code below, if I comment out the first "if" statement, then I get a larger number outputted. Does the continue make the code jump to the top of the loop again? Is the "next test" considered my 2nd if statement? Module mod = current Object obj = null int num = 0 for obj in entire mod do { if (isDeleted obj) continue if (!null obj) num++ } print num"" |
|
![]() |
|
![]() |
|
It's the loop's next test statement. That's whatever is in the while/for/do or whatever that controls execution of the loop, not what happens inside the loop. 'break' and 'continue' treat the whole loop as a single thing, regardless of what's inside:
for ... in ... do { // stuff if (...) continue // more stuff if (...) break // other stuff } In the snippet above, in each pass through the loop 'stuff' always get's done. 'more stuff' only gets done if the first 'if' evaluates false, and 'other stuff' only gets done if the second 'if' evaluates false. If the first 'if' evaluates true, the loop starts again from the top, with the next value from the 'for'. If the second 'if' evaluates true, the whole loop stops. I'm sure it can be said more succinctly (and no doubt someone will...), but maybe that will help for a starter. Taking another quick look at your post, the answer to the two questions are 'yes, it jumps to the top of the loop' and 'no, because it won't get as far as your 2nd if statement'. Paul. ------------------------- Paul dot Tiplady at TRW dot com TRW Automotive |
|
![]() |
|
![]() |
|
Thanks, your answer makes much more sense than the example in the 7.1 reference manual. I ran that code with and without the continue statement and I got the same output each time. That really helped - LOL! :-)
|
|
![]() |
|
![]() |
|
Passing a null parameter always causes a DXL run-time error, so remember to test for null before anything else.
for o in m do { if (null o) continue if (isDeleted o) continue // other stuff .... } ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
...and now for my next question... what exactly does it mean for an object to be null?
|
|
![]() |
|
![]() |
|
quote: Any non-simple data item can be null. It's what it is if it isn't anything else. And it's not the same as empty! I recall a post on the subject somewhere in this forum recently ... pause while I hunt through old posts ... Found it! Check out this post, where there's loads of references to null and some very confusing discussion. I think the upshot is that (non-simple) variables can be:
This applies to strings and Objects at least. Arrays and Skips are something else, so I suspect null doesn't apply (although I'm allowed to be wrong, and I must admit to not having read the manual). I'm also not sure about simple variables. Can (for instance) an int be null? I think not. I don't think that will have helped as much, but it was worth a go, and it's softened the start to my day ![]() Cheers, Paul. ------------------------- Paul dot Tiplady at TRW dot com TRW Automotive |
|
![]() |
|
![]() |
|
>I think the upshot is that (non-simple) variables can be: undefined, defined and null, defined with a value
Which is really similar as pointer handling e.g. in C programming language (which is not surprising as DXL is based on interpreted C) There is a chapter in te DXL Help on null ("The Null constant") which states that null can be used for every derived type, e.g. Object etc. ------------------------- Pekka.Makinen@softqa.fi SoftQA Oy -http://www.softqa.fi/ |
|
![]() |
|
![]() |
|
I don't think you need to check for a null object when it comes out of a loop like that: for obj in mod do; how can obj be null? Yes, when traversing links etc you need to check for null since you may get that as a result: obj = source(link) can be null when you don't have R access to the object or the source module isn't loaded.
- Louie |
|
![]() |
|
![]() |
|
quote: Well......yes. Conceptually I'm not sure of the details, but a null int is apparently zero: int i = null print i i = 0 print (null i) gives
And, Louie: I think you can get a null object after one of those loops, if the set is empty (e.g. no Objects in the Module). Chris Edit: Just came across a section in the manual dealing with null---look under "Operations on all types." Edited: 20-Oct-2006 at 03:25 by Chris Jones |
|
![]() |
|
![]() |
|
None of my for obj loops checks for a null object and I've never had a problem, even for modules with no objects (or no objects visible). If you can produce an example I'd appreciate it.
|
|
![]() |
|
![]() |
|
Errr....maybe that doesn't happen. I thought I'd gotten a null afterwards with a quick loop on an empty module, but now I can't reproduce it. I suspect I may have initialized the Object to null without thinking about it......
|
|
![]() |
Telelogic DOORS
» DXL Exchange
»
continue
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.