最初的夢想語法
最初的夢想語法是指在學習程式語言時,最初接觸和掌握的基本語法規則。對於許多初學者來說,這些基本語法是構建複雜程式的基礎。以下是一些常見程式語言的最初夢想語法:
-
變數聲明與賦值:
- Python:
x = 10
- JavaScript:
let x = 10;
- C:
int x = 10;
- Python:
-
條件語句:
- Python:
if x > 5: print("x is greater than 5")
- JavaScript:
if (x > 5) { console.log("x is greater than 5"); }
- C:
if (x > 5) { printf("x is greater than 5"); }
- Python:
-
循環語句:
- Python:
for i in range(5): print(i)
- JavaScript:
for (let i = 0; i < 5; i++) { console.log(i); }
- C:
for (int i = 0; i < 5; i++) { printf("%d\n", i); }
- Python:
-
函式定義與調用:
- Python:
def greet(name): print("Hello, " + name) greet("Alice")
- JavaScript:
function greet(name) { console.log("Hello, " + name); } greet("Alice");
- C:
void greet(char *name) { printf("Hello, %s\n", name); } greet("Alice");
- Python:
這些語法規則是編程的基礎,掌握了它們,就可以開始構建更複雜的程式。