← Back to list

HarmonyOSNext — — Cangjie Basic Syntax and Structure

This article will delve into the basic syntax and structure of the Cangjie language. These fundamental knowledge lay a solid foundation…

Lhj · 2025-05-22 12:35 · 10 claps · 1.7 min read
#harmony-next #cangjie
Open on Medium ↗
Wiki topics: PFI · Personal Finance LNG · Linguistics & Language

HarmonyOSNext — — Cangjie Basic Syntax and Structure

This article will delve into the basic syntax and structure of the Cangjie language. These fundamental knowledge lay a solid foundation for writing efficient and maintainable code. By understanding statement structures, expressions, comments, and data types, you can use Cangjie for programming with greater confidence.

Keywords

Cangjie basic syntax Statement structure Expression Comment Data type Control structure

I. Basic Syntax

1.1 Statement Structure

The statement structure in Cangjie forms the fundamental building blocks of code, including assignment statements, conditional statements, and loop statements.

Assignment Statements: Used to assign values to variables.

let x: Int64 = 10
println(x)

output:10

Conditional Statements: Used to control the execution flow of a program.

if (x > 0) {
    println("x is +")  
}

output: x is +

for (i in 1..=5) {
    println(i) 
}

output: 1 2 3 4 5

Please translate the following text into English.

1.2 Expressions

Cangjie supports various expressions, including arithmetic operations and logical operations.

Arithmetic Operations: Such as addition, subtraction, etc.

let a: Int64 = 1
let b: Int64 = 2
let sum: Int64 = a + b
println(sum)

output:3

Logical Operations: Such as AND, OR, etc.

if (a > 0 && b < 10) {
    println("a > 0 && b < 10") 
}

output:a > 0 && b < 10

II. Variable Naming and Identifiers Overview

In the Cangjie programming language, developers assign names to program elements, which are called identifiers. Identifiers are categorized into ordinary identifiers and raw identifiers, each adhering to distinct naming rules.

III. Comments

Comments are used to improve code readability and maintainability. In Cangjie, there are two types of comments:

3.1 Single-Line Comments

Single-line comments use // and can be used to explain code or temporarily block code lines.

println("Welcome to Cangjie!")

output:Welcome to Cangjie!

3.2 Multi-Line Comments

Multi-line comments are enclosed within /* */ and are suitable for longer explanations or blocking multiple lines of code.

func factorial(n: Int): Int {
}

IV. Data Types

Cangjie supports several data types, including:

Integer Types、Floating-Point Types、String Type、Boolean Type

let age: Int64 = 25
let height: Float64 = 1.75
let name: String = "Cangjie" 
let isAdult: Bool = true

V. Control Structures

Control structures are used to manage the execution flow of a program, including conditional logic and loop constructs.

Use if, else if, and else for conditional judgment.

The for loop and while loop are used to repeatedly execute code blocks.

Summary

This article provides a comprehensive introduction to the basic syntax and structure of the Cangjie language, including statement structures, expressions, comments, data types, and control structures. Mastering these fundamental concepts will lay a solid foundation for subsequent programming learning and serve as the basis for creating efficient and maintainable code.


메타데이터
post_id
18efe1555eb8
slug
harmonyosnext-cangjie-basic-syntax-and-structure-18efe1555eb8
url
https://medium.com/@lhj18250199598/harmonyosnext-cangjie-basic-syntax-and-structure-18efe1555eb8
canonical_url
https://medium.com/@lhj18250199598/harmonyosnext-cangjie-basic-syntax-and-structure-18efe1555eb8
author_url
https://medium.com/@lhj18250199598
status
ok
fetched_at
2026-07-25 17:06:40