Why is there a colon in some Programs between 2 statements

Manu

I was going through a QB64 tutorial and saw the following program structure for printing numbers from 1 to 10 →

FOR x = 1 to 10: PRINT x: NEXT x

I have never seen such a kind of QB64 program. What do those colons : mean? Are they anything different?

Mrigank Pawagi

I the QB64 IDE, you do not need to terminate statements using a special character like in other languages. This also means that you CANNOT expand a statement into multiple lines. Consider the following IF...THEN...ELSE... code block.

IF 
x = 1 
THEN
'Do something
...

This wouldn't be interpreted, as each new line terminates the statement. The above code would be parsed as:

Statement 1: IF [Incomplete Statement]
Statement 2: x = 1 [assign value 1 to x]
Statement 3: THEN [No such statement]
...

This means that you must constrain a single statement over a single line.

However, on the contrary, you are allowed to use multiple statements on a single line. In this case, since statements cannot be terminated with new lines, you must terminate them with a colon :. In your case,

FOR x = 1 to 10: PRINT x: NEXT x

This would be parsed as:

Statement 1: FOR x = 1 to 10 [Initialize a value and set a condition for a FOR...NEXT loop]
Statement 2: PRINT x [Print the value]
Statement 3: NEXT x [Close the FOR...NEXT code block, and iterate the variable]

There is no significant difference between using a colon or a new line for termination, but personally, I would recommend using new lines as they make the code considerably cleaner to look and easier to read. However, at times when there are multiple short and less important statements one after the other, you can combine them on a single line with colons to make your code shorter and concise to look.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why can some programs be installed without administrator privileges?

分類Dev

Why some programs execute with undefined behavior and others don't?

分類Dev

Problem of understanding, Why these 2 programs take 3 and 6 seconds respectively

分類Dev

Why doesn't stdbuf line buffer the output of some simple c programs

分類Dev

Some programs print errors to stdout instead of stderr, and don't set $? when an error occurs. Why?

分類Dev

Why do I have to download a .deb file to update some already installed programs?

分類Dev

Why doesn't the Python 2D array index order matter when used with colon ( : )

分類Dev

Why do I get a null object reference (NullPointerException) on onBackPressed in some statements and not in anothers? (Navigation Drawer - Android)

分類Dev

Why use != null in if statements?

分類Dev

Some programs not found when used with sudo

分類Dev

Why do .NET console programs not deadlock the way UI programs do?

分類Dev

What is the difference between using the colon and as syntax for declaring type?

分類Dev

Why does this C++ program work in some compilers but not others? What is the major difference between c++ compilers?

分類Dev

Grep between some period

分類Dev

Why do these small D programs behave differently?

分類Dev

Why can invoked functions be prefixed with a name + colon in JavaScript

分類Dev

Why can invoked functions be prefixed with a name + colon in JavaScript

分類Dev

Why there are 2px space added between zero margin button?

分類Dev

What is the difference between Expressions and Statements in Scala

分類Dev

How comma operator is used between the statements?

分類Dev

why are my if statements not displaying on my website?

分類Dev

Why does kcov calculate incorrect code coverage statistics for Rust programs?

分類Dev

Why programs nowadays install itself into AppData/Local in Windows?

分類Dev

Why my website giving "The site ahead contains harmful programs" error?

分類Dev

Why doesn't ps -al display my java programs?

分類Dev

JavaScript: why are some functions not methods?

分類Dev

Why are some files and folders hidden?

分類Dev

regex to extract a string between 5th and 6th colon without space

分類Dev

ruby code: why put colon in front of variable name (inside initialize method)

Related 関連記事

  1. 1

    Why can some programs be installed without administrator privileges?

  2. 2

    Why some programs execute with undefined behavior and others don't?

  3. 3

    Problem of understanding, Why these 2 programs take 3 and 6 seconds respectively

  4. 4

    Why doesn't stdbuf line buffer the output of some simple c programs

  5. 5

    Some programs print errors to stdout instead of stderr, and don't set $? when an error occurs. Why?

  6. 6

    Why do I have to download a .deb file to update some already installed programs?

  7. 7

    Why doesn't the Python 2D array index order matter when used with colon ( : )

  8. 8

    Why do I get a null object reference (NullPointerException) on onBackPressed in some statements and not in anothers? (Navigation Drawer - Android)

  9. 9

    Why use != null in if statements?

  10. 10

    Some programs not found when used with sudo

  11. 11

    Why do .NET console programs not deadlock the way UI programs do?

  12. 12

    What is the difference between using the colon and as syntax for declaring type?

  13. 13

    Why does this C++ program work in some compilers but not others? What is the major difference between c++ compilers?

  14. 14

    Grep between some period

  15. 15

    Why do these small D programs behave differently?

  16. 16

    Why can invoked functions be prefixed with a name + colon in JavaScript

  17. 17

    Why can invoked functions be prefixed with a name + colon in JavaScript

  18. 18

    Why there are 2px space added between zero margin button?

  19. 19

    What is the difference between Expressions and Statements in Scala

  20. 20

    How comma operator is used between the statements?

  21. 21

    why are my if statements not displaying on my website?

  22. 22

    Why does kcov calculate incorrect code coverage statistics for Rust programs?

  23. 23

    Why programs nowadays install itself into AppData/Local in Windows?

  24. 24

    Why my website giving "The site ahead contains harmful programs" error?

  25. 25

    Why doesn't ps -al display my java programs?

  26. 26

    JavaScript: why are some functions not methods?

  27. 27

    Why are some files and folders hidden?

  28. 28

    regex to extract a string between 5th and 6th colon without space

  29. 29

    ruby code: why put colon in front of variable name (inside initialize method)

ホットタグ

アーカイブ