键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

While

While[condition, body]

Repeatedly evaluates body as long as condition evaluates to #t. KSL does not provide break or continue statements; loop control is achieved by updating variables within the loop using Update.

  • Returns Unit[].
Let[i, 0];
While[Less[i, 3], Block[
  Print[i],
  Update[i, Add[i, 1]]
]];

Write

Write[path, append, content]

Writes the string content to the file at path.

  • append is #t to append to an existing file, or #f to overwrite.
  • Returns Unit[].
Write["log.txt", #f, Concat["First line", #10]];
Write["log.txt", #t, Concat["Second line", #10]];

WriteTerm

WriteTerm[s]

Writes the string s directly to the terminal, supporting ANSI escape sequences for cursor control and styling.

  • Returns Unit[].
WriteTerm["\x1b[H"];   (* Moves cursor to home position *)
WriteTerm["\x1b[2J"];  (* Clears the screen *)
Print["Hello, terminal!"];