(redirection from Notes For Programmers Used To / BASICVariants)
Comparisons for programmers familiar with variants of BASIC
 | | BASIC | D | |
| PRINT "Hello World" | printf("Hello World\n") | |
| CONST MYPI# = 3.14 | const double myPi = 3.14 | |
| CONST T$ = "Some Constant" | const char[] T = "Some Constant" | |
| DIM S$ | char[] S | |
| DIM I% | int I | |
| I% = 5 | I = 5 | |
| S$ = "Some String" | S = "Some String" | |
| I% = 2 : J% = 3 | I = 2; J = 3; | |
| ' Single line comment | // Single line comment | |
| REM Single line comment | // Single line comment | |
| IF I% = 0 THEN I% = 5 | if(I == 0) I = 5 | |
| IF I% = 0 THEN S$ = "Yes" ELSE S$ = "No" | if(I == 0) S = "Yes"; else S = "No"; | |
IF I% = 0 THEN S$ = "Yes" D$ = "Ja" ELSE S$ = "No" D$ = "Nein" END IF | if(I == 0) { S = "Yes"; D = "Ja"; } else { S = "No"; D = "Nein"; } | |
|
|
Some Major Differences From BASIC
- Identifier names are case-sensitive. (MyVariable, MYVARIABLE, and myvariable are three different identifiers.)
- Keywords such as "if" and "for" are also case-sensitive. (The symbol "if" is a keyword, "IF" isn't a keyword.)
- All variables must be declared before use and assigned a specific type.
- Printing to the console window: printf is much trickier than PRINT (see HowTo/printf).
- All statements end with a semi-colon. Carriage returns and line feeds are ignored by the compiler (except within literal strings).
Guide for Finding the Right String Function
Add "import std.string;" to use these functions.
 | | BASIC | D |
| InStr | find |
| InStrRev | rfind |
| Val(i%) | atoi(i) |
| Val(f#) | atof(f) |
| LTrim$ | stripl |
| RTrim$ | stripr |
| Trim$ | strip |
| LCase$ | tolower |
| UCase$ | toupper |
|
|
Related