Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Paul Tiplady, on Thursday, October 12, 2006 3:25 PM

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.
 12-Oct-2006 14:16
User is offline View Users Profile Print this message


Al Lione

Posts: 59
Joined: 13-Jul-2004

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""



Report this to a Moderator Report this to a Moderator
 12-Oct-2006 14:38
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Answer 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.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 12-Oct-2006 15:27
User is offline View Users Profile Print this message


Al Lione

Posts: 59
Joined: 13-Jul-2004

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! :-)
Report this to a Moderator Report this to a Moderator
 12-Oct-2006 16:09
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 12-Oct-2006 18:34
User is offline View Users Profile Print this message


Al Lione

Posts: 59
Joined: 13-Jul-2004

...and now for my next question... what exactly does it mean for an object to be null?
Report this to a Moderator Report this to a Moderator
 13-Oct-2006 08:31
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

quote:

Originally posted by: Al Lione
what exactly does it mean for an object to be null?

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:
    undefined

    defined and null

    defined with a value


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
Report this to a Moderator Report this to a Moderator
 13-Oct-2006 09:32
User is offline View Users Profile Print this message


Pekka Mäkinen

Posts: 276
Joined: 18-Mar-2004

>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/
Report this to a Moderator Report this to a Moderator
 17-Oct-2006 00:05
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 20-Oct-2006 03:11
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

quote:

Originally posted by: Paul Tiplady
Can (for instance) an int be null?



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

    0
    true


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
Report this to a Moderator Report this to a Moderator
 24-Oct-2006 23:22
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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.
Report this to a Moderator Report this to a Moderator
 24-Oct-2006 23:44
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

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......
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.