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