Need help with 'if' statement

This is a discussion on Need help with 'if' statement within the mumps forums in Programming Languages category; Given: set i=1,j=2,k=3 what does the following say: if i=0!(j=2) write "yes",! ^^^^^^^^^ this is confusing me. What is the 'nl' command doing there? -- Duke Normandin...

Go Back   Application Development Forum > Programming Languages > mumps

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 05-03-2008, 11:23 PM
Duke Normandin
Guest
 
Default Need help with 'if' statement

Given:

set i=1,j=2,k=3

what does the following say:

if i=0!(j=2) write "yes",!
^^^^^^^^^
this is confusing me. What is the 'nl' command doing there?
--
Duke Normandin
Reply With Quote
  #2  
Old 05-04-2008, 01:02 AM
Rod Dorman
Guest
 
Default Re: Need help with 'if' statement

In article <D_9Tj.255$Yp.44@edtnps92>,
Duke Normandin <dukeofperl@ml1.net> wrote:
>Given:
>
>set i=1,j=2,k=3
>
>what does the following say:
>
>if i=0!(j=2) write "yes",!
> ^^^^^^^^^
>this is confusing me. What is the 'nl' command doing there?


Pay attention to the difference between an expression and a format.

--
-- Rod --
rodd(at)polylogics(dot)com
Reply With Quote
  #3  
Old 05-04-2008, 03:39 AM
lmv
Guest
 
Default Re: Need help with 'if' statement

On May 3, 10:23 pm, Duke Normandin <dukeofp...@ml1.net> wrote:
> Given:
>
> set i=1,j=2,k=3
>
> what does the following say:
>
> if i=0!(j=2) write "yes",!
> ^^^^^^^^^
> this is confusing me. What is the 'nl' command doing there?
> --
> Duke Normandin


The ! symbol is an "or" when used with an IF command or as part of a
condition. It is a "nl" when used with the write command.

--Leane
Reply With Quote
  #4  
Old 05-04-2008, 05:33 AM
Rob Tweed
Guest
 
Default Re: Need help with 'if' statement

Here's a tip to make sure you don't fall foul of MUMPS' unusual
if/else construction and its reliance on $t which can inadvertently
cause you problems (another area of weirdness that can cause hours of
debugging grief)

As a matter of course, I structure them as follows:

if condition do
. ; whatever needed for main condition
.; etc....
else do
. ; whatever needed for else condition
. ;etc...

This use of "dot syntax" gives you the syntactical equivalent to the
C-style:

if (condition) {
//whatever you need to do
}
else {
//whatever else you need to do
}

so it's a reasonably familiar construct for someone new to MUMPS, and
also will behave as you'd expect.

Note the 2 spaces between "else" and "do"



On Sun, 4 May 2008 00:39:17 -0700 (PDT), lmv <lverhulst@gmail.com>
wrote:

>On May 3, 10:23 pm, Duke Normandin <dukeofp...@ml1.net> wrote:
>> Given:
>>
>> set i=1,j=2,k=3
>>
>> what does the following say:
>>
>> if i=0!(j=2) write "yes",!
>> ^^^^^^^^^
>> this is confusing me. What is the 'nl' command doing there?
>> --
>> Duke Normandin

>
>The ! symbol is an "or" when used with an IF command or as part of a
>condition. It is a "nl" when used with the write command.
>
>--Leane


---

Rob Tweed
Company: M/Gateway Developments Ltd
Registered in England: No 3220901
Registered Office: 58 Francis Road,Ashford, Kent TN23 7UR

Web-site: http://www.mgateway.com

SlipstreamUSA: April 2, Renaissance Hotel, Orlando
http://www.OutOfTheSlipstream.com
Reply With Quote
  #5  
Old 05-04-2008, 09:46 AM
Duke Normandin
Guest
 
Default Re: Need help with 'if' statement

On 2008-05-04, lmv <lverhulst@gmail.com> wrote:
> On May 3, 10:23 pm, Duke Normandin <dukeofp...@ml1.net> wrote:
>> Given:
>>
>> set i=1,j=2,k=3
>>
>> what does the following say:
>>
>> if i=0!(j=2) write "yes",!
>> ^^^^^^^^^
>> this is confusing me. What is the 'nl' command doing there?
>> --
>> Duke Normandin

>
> The ! symbol is an "or" when used with an IF command or as part of a
> condition. It is a "nl" when used with the write command.
>
> --Leane


Thanks, Leane! The tutorial I'm using had covered the fact that `!' is
used to mean `or' as well, but I completely missed it. My bad!

[Rod]

Good advise, of course. Because of the duality of some Mumps syntax, I
have to learn to keep that in mind at all times.

[Rob]

What a great suggestion -- especially for me with my Perl background.
I must remember those 2 spaces, though......

Thanks everybody! and have a great weekend! L8r...
--
Duke Normandin
Reply With Quote
  #6  
Old 05-04-2008, 03:43 PM
Aaron Seidman
Guest
 
Default Re: Need help with 'if' statement

> What a great suggestion -- especially for me with my Perl background.
> I must remember those 2 spaces, though......


One way to remember is to think of all M commands as containing two spaces:

<previous command or linestart> Commandword Space Argument(s) Space

where a nl may be substituted for the last space and if there are no
arguments (e.g. following the ELSE command) there still have to be two spaces.

Aaron
Reply With Quote
  #7  
Old 05-04-2008, 07:07 PM
Duke Normandin
Guest
 
Default Re: Need help with 'if' statement

On 2008-05-04, Aaron Seidman <aaron@imaginative-illustration.com> wrote:
> > What a great suggestion -- especially for me with my Perl background.
> > I must remember those 2 spaces, though......

>
> One way to remember is to think of all M commands as containing two
> spaces:
>
><previous command or linestart> Commandword Space Argument(s) Space

| |
| |
+> 2 spaces each <+
Is this what you mean?

> where a nl may be substituted for the last space and if there are no
> arguments (e.g. following the ELSE command) there still have to be
> two spaces.
>
> Aaron


Thanks for your input Aaron!
--
Duke Normandin
Reply With Quote
  #8  
Old 05-05-2008, 12:43 AM
Aaron Seidman
Guest
 
Default Re: Need help with 'if' statement

Duke Normandin wrote:
>> One way to remember is to think of all M commands as containing two
>> spaces:
>>
>> <previous command or linestart> Commandword Space Argument(s) Space

> | |
> | |
> +> 2 spaces each <+
> Is this what you mean?


Each command must have exactly one space between the commandword (e.g.
WRITE, IF, DO, etc.) and the argument list and there must be one or more
spaces or nl after the argument(s), depending whether there is anything else
following.

Some examples (NB: the semicolon ";" is the comment character):

|space|WRITE<sp>"FOO"<nl> ; One vommand on the line, line ends with newline
| tab |


|space|WRITE<sp>"FOO","BAR"<sp>READ<sp>VAR<nl> ; two commands on line
| tab |


|space|ELSE<sp><sp>KILL<sp>VAR<nl> ; ELSE command has empty arg list
| tab |

Aaron
Reply With Quote
  #9  
Old 05-05-2008, 07:39 AM
Duke Normandin
Guest
 
Default Re: Need help with 'if' statement

On 2008-05-05, Aaron Seidman <aaron@imaginative-illustration.com> wrote:
> Duke Normandin wrote:
>>> One way to remember is to think of all M commands as containing two
>>> spaces:
>>>
>>> <previous command or linestart> Commandword Space Argument(s) Space

>> | |
>> | |
>> +> 2 spaces each <+
>> Is this what you mean?

>
> Each command must have exactly one space between the commandword (e.g.
> WRITE, IF, DO, etc.) and the argument list and there must be one or more
> spaces or nl after the argument(s), depending whether there is anything else
> following.
>
> Some examples (NB: the semicolon ";" is the comment character):
>
>|space|WRITE<sp>"FOO"<nl> ; One vommand on the line, line ends with newline
>| tab |
>
>
>|space|WRITE<sp>"FOO","BAR"<sp>READ<sp>VAR<nl> ; two commands on line
>| tab |
>
>
>|space|ELSE<sp><sp>KILL<sp>VAR<nl> ; ELSE command has empty arg list
>| tab |
>
> Aaron


I now understand what you are getting at. Thanks!
--
Duke Normandin
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:38 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.