To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 12946
12945  |  12947
Subject: 
Re: Semicolon (;) Confusion
Newsgroups: 
lugnet.robotics
Date: 
Fri, 27 Oct 2000 18:12:16 GMT
Original-From: 
John A. Tamplin <{jat@}NoMoreSpam{liveonthenet.com}>
Viewed: 
541 times
  
On Fri, 27 Oct 2000, Jerry Kalpin wrote:

In some cases Mark Overmars great RCX Command Center does not flag syntax
errors for incorrect use of an ending semicolon, as in the example below.
Could someone please explain how semicolons work in NQC?  Perhaps there is a
good reason for *not* flagging syntax errors in those cases.

//a flasher program
task main()
{
    SetSensor(SENSOR_1,SENSOR_TOUCH);
    while (true)   // A semicolon here disables program
    {
        if (SENSOR_1 == 1)  //a semicolon here runs the flasher all the time
        {
            On (OUT_B);
            Wait (10);
            Off (OUT_B);
            Wait (100);
        }
    }
}

NQC implements a syntax similar to C.  In C, while and if statements have
a single statement that is executed if the condition is true.  A null
statement is a valid statement, and a block of statements enclosed in {}
can be substituted or a statement.  So, if you add a semicolon after the
while:

while(true);
{
...
}

You have a valid statement that loops continuously doing nothing.  The
rest of the program is never reached.  Likewise, if you put it after the
if, the null statement is executed if the condition is true, and then the
following block of statements is unconditionally executed.

John A. Tamplin LiveOnTheNet.COM, Inc.
jat@LiveOnTheNet.COM 2104 West Ferry Way
256/705-7007 - FAX 256/705-7100 Huntsville, AL 35801



Message has 1 Reply:
  Re: Semicolon (;) Confusion
 
John, Thanks for that answer. That same question has haunted me for some time. -- Bob Fay rfay@we.mediaone.net The Shop (URL) A. Tamplin" <lego-robotics@crynwr.com> wrote in message news:Pine.A32.3.91.1...net.com... (...) syntax (...) below. (...) (...) (24 years ago, 27-Oct-00, to lugnet.robotics)

Message is in Reply To:
  Semicolon (;) Confusion
 
In some cases Mark Overmars great RCX Command Center does not flag syntax errors for incorrect use of an ending semicolon, as in the example below. Could someone please explain how semicolons work in NQC? Perhaps there is a good reason for *not* (...) (24 years ago, 27-Oct-00, to lugnet.robotics)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR