how to program
HOW TO PROGRAM . IT - learn how to program - online interactive programming tutorial and programming course
0
Statements on the same line

Lesson 05: Multiple statements can go on the same line, as in...

Program Code:
Output:


With a lot of programming languages, the white space between statements (white space includes normal spacebar characters, tabs, line breaks, etc) are ignored, so it it really up to the programmer what spacing is used. This is especially the case with C-like languages (e.g. C, C++, C#, Java, JavaScript, PHP, etc) which use semicolons ; to separate statements, but it is less the case with other languages (e.g. VB, VB.NET, etc) which use line breaks to imply special meaning within the code.

White space can also go within parts of statements, for instance there are spaces between the ( and the " in the env.out( "Hello World" ) statement

Multiple statements per line may or may not help with program clarity, and in most cases one major statement per line is preferred. This can also help with debugging.

Exercises:

1. Add spaces between the statements to see that it does not affect how the program is run.
2. Take out some spaces.
3. Does the code read better with statements on one line or on different lines? Add line breaks between the statements by placing the cursor in the appropriate place and pressing enter (return).

To return to previous page click here

 
0
by running the tutorial programs on this site, you are agreeing to our terms and conditions (please check these first).
Mon 10 Dec 2018 web design | login © 2018 Abstract Worlds Ltd