By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

syntax ok?

P: n/a
emacs fails to hightlight the following line properly, when
I changed 'continue' to 'goto skip'.
So just to be sure there isn't any weired rule,
does the following do what I want?

if( yLog) if( y <= 0.0) goto skip; else y = log10( y);

Thanks,
marc

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
m_schellens wrote:
emacs fails to hightlight the following line properly, when
I changed 'continue' to 'goto skip'.
So just to be sure there isn't any weired rule,
does the following do what I want?

if( yLog) if( y <= 0.0) goto skip; else y = log10( y);


It's well-formed. Please don't do it. Google for 'goto' to learn why. The
best way to prematurely exit a block is to return.

emacs obviously has a bug in its hiliter that bites code that most emacs
users would never write.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


Jul 23 '05 #2

P: n/a
"Phlip" <ph*******@yahoo.com> wrote in message
news:q0***************@newssvr17.news.prodigy.com. ..
does the following do what I want? if( yLog) if( y <= 0.0) goto skip; else y = log10( y);
It's well-formed. Please don't do it. Google for 'goto' to learn why. The
best way to prematurely exit a block is to return. emacs obviously has a bug in its hiliter that bites code that most emacs
users would never write.


Moreover, whether it does what you want depends on what you want. Do you
want this?

if( yLog) { if( y <= 0.0) goto skip; else y = log10( y); }

or do you want this?

if( yLog) { if( y <= 0.0) goto skip; } else y = log10( y);

They're different. (Without the { }, the first one of these examples is
what you get)
Jul 23 '05 #3

P: n/a
On 11 Apr 2005 07:19:08 -0700, m_*********@hotmail.com
<m_*********@hotmail.com> wrote:
emacs fails to hightlight the following line properly, when
I changed 'continue' to 'goto skip'.
So just to be sure there isn't any weired rule,
does the following do what I want?

if( yLog) if( y <= 0.0) goto skip; else y = log10( y);


1. there is an incorrect semicolon after "skip", else cannot be a
standalone statement.

2. much clearer style would be:

if( yLog)
{
if( y <= 0.0)
{
goto skip;
}
else
{
y = log10( y);
}
}

this is what your code would do without the wrong semicolon.

3. re-think on how you could avoid the "goto"
Jul 23 '05 #4

P: n/a

"ulrich" <ua********@aon.at> schrieb im Newsbeitrag
news:opso2pf6xan2mgp5@innsbruck-neu...
On 11 Apr 2005 07:19:08 -0700, m_*********@hotmail.com
<m_*********@hotmail.com> wrote:
emacs fails to hightlight the following line properly, when
I changed 'continue' to 'goto skip'.
So just to be sure there isn't any weired rule,
does the following do what I want?

if( yLog) if( y <= 0.0) goto skip; else y = log10( y);
1. there is an incorrect semicolon after "skip", else cannot be a
standalone statement.


You're right that "else" cannot be a standalone statement, but in this case
it isn't. The statement above could be rewritten as

if( yLog)
if( y <= 0.0)
goto skip;
else y = log10( y);

2. much clearer style would be:

if( yLog)
{
if( y <= 0.0)
{
goto skip;
}
else
{
y = log10( y);
}
}

this is what your code would do without the wrong semicolon.
The semicolon is all right. See Andrew's post regarding the effects of the
code.

3. re-think on how you could avoid the "goto"


I cannot agree more!!

Cheers
Chris
Jul 23 '05 #5

P: n/a
On 2005-04-11 11:03:32 -0400, ulrich <ua********@aon.at> said:
On 11 Apr 2005 07:19:08 -0700, m_*********@hotmail.com
<m_*********@hotmail.com> wrote:
emacs fails to hightlight the following line properly, when
I changed 'continue' to 'goto skip'.
So just to be sure there isn't any weired rule,
does the following do what I want?

if( yLog) if( y <= 0.0) goto skip; else y = log10( y);
1. there is an incorrect semicolon after "skip", else cannot be a
standalone statement.


There is nothing wrong with that semicolon. The above line is equivalent to:

if( yLog)
if( y <= 0.0)
goto skip;
else
y = log10(y);

In fact, you have the exact same semicolon in your example...
2. much clearer style would be:

if( yLog)
{
if( y <= 0.0)
{
goto skip; ....right here------^ }
else
{
y = log10( y);
}
}


--
Clark S. Cox, III
cl*******@gmail.com

Jul 23 '05 #6

P: n/a
On Mon, 11 Apr 2005 17:34:17 +0200, Chris Theis
<Ch*************@nospam.cern.ch> wrote:

"ulrich" <ua********@aon.at> schrieb im Newsbeitrag
news:opso2pf6xan2mgp5@innsbruck-neu...
> if( yLog) if( y <= 0.0) goto skip; else y = log10( y);


[...]

2. much clearer style would be:

if( yLog)
{
if( y <= 0.0)
{
goto skip;
}
else
{
y = log10( y);
}
}

this is what your code would do without the wrong semicolon.


The semicolon is all right. See Andrew's post regarding the effects of
the
code.


you're right. obviously i have typed my answer too quickly...


3. re-think on how you could avoid the "goto"


I cannot agree more!!


:)
Jul 23 '05 #7

P: n/a
Thanks everybody.
As I said, just wanted to make sure because so far almost always emacs
C++ mode did something 'strange' there was a reason (ie. missing
semicolon etc).
I know about the use of goto, but in some few cases a goto can be
cleaner.
(for what it's worth: return was no option here since there are
statements following)
Thanks,
marc

Jul 23 '05 #8

P: n/a
mschell...@gmail.com wrote:
Thanks everybody.
As I said, just wanted to make sure because so far almost always
emacs C++ mode did something 'strange' there was a reason (ie.
missing semicolon etc). I know about the use of goto, but in
some few cases a goto can be cleaner.
Cleaner? Gotos? wash your mouth out at once ;-)
(for what it's worth: return was no option here since there are
statements following)


FWIW, a return statement does not have to be the last statement in a
function (if that's what you were implying). You may also have as many
returns as you like.

int silly()
{
return 0;
std::cout << "Don't expect to see this...";
return 1;
std::cout << " ...or this";
return 2;
}

Anyway, I'm not sure that jumping out of functions at odd places via
returns is that much better an idea than gotos (needless to say I do it
myself all the time...).

Anyone remember "Structured Programming" (as taught, usually in Pascal
in the early 80's)?

--
Lionel B

Jul 23 '05 #9

P: n/a
(for what it's worth: return was no option here since there are
statements following


.... the goto statement.
These statements have to be executed after the goto statement.

Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.