I.T. Discussion Community!
-Collapse +Expand
C#
Search C# Group:

Advanced
-Collapse +Expand C# To/From
To/FromCODEGuides
-Collapse +Expand C# Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C# Store
PRESTWOODSTORE
   ► KBTo/From GuidesReferenceLanguage Basics  Print This    All Groups  

End of Statement (Cross Ref > Language Basics)

End of Statement

Languages Focus

In coding languages, common End of statement specifiers include a semicolon and return (others exist too). Also of concern when studying a language is can you put two statements on a single code line and can you break a single statement into two or more code lines.

Access VBA:   Return

A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

Syntax Example:
MsgBox "Hello1"
MsgBox "Hello2"
MsgBox "Hello3"

'The following commented code on a single line does not work...
'MsgBox "Hello4" MsgBox "Hello5"

'Two or more lines works too with a space+underscore:
MsgBox _
"Hello6";


More Info

ASP Classic:   Return

A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

Syntax Example:
Response.Write("Hello1")
Response.Write("Hello2")
Response.Write("Hello3")

'The following commented code on a single line does not work...
' Response.Write("Hello4") Response.Write("Hello5")

'Two or more lines works too with a space+underscore:
Response.Write _
("Hello6")


More Info

C#:   ;

C# uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
Console.WriteLine("Hello1");
Console.WriteLine("Hello2");
Console.WriteLine("Hello3");

//Same line works too:
Console.WriteLine("Hello4"); Console.WriteLine("Hello5");
 
//Two or more lines works too: 
Console.
  WriteLine
("Hello6");



Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Beginner

1 Beginner Level Question

Question #1: Multiple Choice

Which of the following lines of code will compile?

Answer:
1. 
MessageBox.Show("a");MessageBox.Show('b');
2. 
MessageBox
    .Show
     (
    "d"
    );
3. 
MessageBox
  .Show("c");
4. 

All of the above.

5. 

None of the above.

More Info

 

C++:   ;

C++ uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
printf("Hello1");
printf("Hello2");
  
printf("Hello3"); printf("Hello4");
  
printf
   ("Hello5");

More Info

C++/CLI:   ;

Same as standard C++. C++ uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Syntax Example:
//.Net WinForms example.
//Add, using namespace System::Windows::Forms;
MessageBox::Show("Hello1");
MessageBox::Show("Hello2");
MessageBox::Show("Hello3");
   
MessageBox::Show("Hello4"); MessageBox::Show("Hello5"); 
  
MessageBox:: 
  Show 
    ("Hello6");

More Info

Corel Paradox:   whitespace

ObjectPAL is a bit unique in that it doesn't use a semicolon nor a return to mark the end of a line, it uses whitespace which can be a return, space, or tab. This is a bit unusual but does allow for some nice formatting of code.

Syntax Example:
msgInfo("", "Hello1")
msgInfo("", "Hello2")
msgInfo("", "Hello3")

;The following single line of code also works.
msgInfo("", "Hello4") msgInfo("", "Hello5")

;Two or more works too:
msgInfo
("", "Hello6")




Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: True or False?

It is legal to put two code statements on a single line as in the following:

msgInfo("", "hello")  msgInfo("", " world")
Answer:
  • True
  • False
  • More Info

     

    Delphi:   ;

    Object Pascal uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code and put a single statement on two or more code lines if you wish.

    Syntax Example:
    WriteLn('Hello1');
    WriteLn('Hello2');
    WriteLn('Hello3');

    //Same line works too:
    WriteLn('Hello4'); WriteLn('Hello5');

    //Two or more lines works too:
    WriteLn
    ('Hello6');




    Linked Certification Question(s)

    The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

    Beginner

    1 Beginner Level Question

    Question #1: Multiple Choice

    Which of the following lines of code will compile?

    Answer:
    1. 
    WriteLn('Hello');  WriteLn(' world');
    2. 
    WriteLn
      ('Hello');
    3. 
    WriteLn
      (
      'hello'
      );
    4. 

    All of the above.

    5. 

    None of the above.

    More Info

     

    Delphi Prism:   ;

    Object Pascal uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code and put a single statement on two or more code lines if you wish.

    Syntax Example:
    MessageBox.Show("Hello1");
    MessageBox.Show("Hello2");
    MessageBox.Show("Hello3");

    //Same line works too:
    MessageBox.Show("Hello4");  MessageBox.Show("Hello5");

    //Two or more lines works too:
    MessageBox.Show
    ("Hello6");


    Linked Certification Question(s)

    The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

    Beginner

    1 Beginner Level Question

    Question #1: Multiple Choice

    Which of the following lines of code will compile?

    Answer:
    1. 
    MessageBox.Show("a");MessageBox.Show('b');
    2. 
    MessageBox
      .Show("c");
    3. 
    MessageBox
        .show
         (
        "d"
        );
    4. 

    All of the above.

    5. 

    None of the above.

    More Info

     

    Java:   ;

    Syntax Example:
    System.out.println("Hello");

    JavaScript:   ; is optional

    In JavaScript, using a semicolon at the end of statements is optional. You might think a semicolon then is just another comment specifier but it is not. The semicolon is an optional end of statement specifier. To put two statements on a single code line, you must use a semicolon. However, the semicolon is optional, but probably confusing, when you break a single statement into multiple code lines.

    Syntax Example:
    document.write("Hello1");
    document.write("Hello2");

    //Semicolons are optional:
    document.write("Hello3")
    document.write("Hello4")

    //This works too but only if you use a semicolon:
    document.write("Hello5"); document.write("Hello6");

    //Two lines also works:
    document.write
    ("Hello7")

    Multiple Statements on a Single Code Line

    You can put multiple statements on a single code line so long as you end each statement with a semicolon. The last semicolon is optional.

    For example:

    document.write("Hello8");  document.write("Hello9"); document.write("Hello10")
    document.write("Hello11");

    Notice no semicolon after document.write("Hello10").

    JavaScript End of Statement Recommendation

    Should I use a semicolon or not?

    Because the semicolon is optional, many JavaScript coders opt to not use it because it's extra typing. This is especially true for developers coming from Visual Basic, ObjectPAL, and other languages that use a return for an end of statement. Developers coming from Delphi, C++, C#, C++, and other languages that use a semicolon tend to use a semicolon consistently with JavaScript. My recomendation to you is to always use the semicolon for clarity and is required under some situations (like putting two statements on a single code line).

    More Info

    Code:  JavaScript End of Statement (; is optional)

    Perl:   ;

    Syntax Example:
    print "Hello";

    PHP:   ;

    Syntax Example:
    echo "Hello";

    VB Classic:   Return

    A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

    Syntax Example:
    MsgBox "Hello1"
    MsgBox "Hello2"
    MsgBox "Hello3"

    'The following commented code
    'on a single line does not work...
    'MsgBox "Hello4" MsgBox "Hello5"

    'Two or more lines works too with a space+underscore:
    MsgBox _
    "Hello6";


    More Info

    VB.Net:   Return

    A return marks the end of a statement and you cannot combine statements on a single line of code. You can break a single statement into two or more code lines by using a space and underscore " _".

    Syntax Example:
    Console.WriteLine("Hello1")
    Console.WriteLine("Hello2")
    Console.WriteLine("Hello3")

    'The following commented code
    'on a single line does not work...
    'Console.WriteLine("Hello4") Console.WriteLine("Hello5")

    'Two or more lines works too with a space+underscore:
    Console.WriteLine _
    "Hello6";




    Linked Certification Question(s)

    The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

    Beginner

    2 Beginner Level Questions

    Question #1: True or False?

    To split a statement into two or more lines use a space plus an underscore " _" as in the following:

    MessageBox. _
    Show _
    ("hello")
    Answer:
  • True
  • False
  • Question #2: True or False?

    In VB.Net, you can combine multiple statements on one line as in the following:

    s = "Mike" MessageBox.Show(s)

    Answer:
  • True
  • False
  • More Info

     





    Follow PrestwoodBoards on: 


    ©1995-2020 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech