Movatterモバイル変換


[0]ホーム

URL:


  1. WebAssembly
  2. Reference
  3. WebAssembly Steuerflussanweisungen
  4. loop

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten.Erfahre mehr über dieses Experiment.

View in EnglishAlways switch to English

loop: Wasm-Textinstruktion

Dieloop-Anweisung erstellt ein Label, zu dem später mit einembr verzweigt werden kann. Die Loop-Instruktion führt nicht von selbst eine Schleife aus; es ist notwendig, zu ihr zu verzweigen, um tatsächlich eine Schleife zu erstellen.

Dieloop-Anweisung ist das Gegenteil derblock-Anweisung, in dem Sinne, dass ein Verzweigen zu einerloop zum Anfang der Schleife springt, während ein Verzweigen zu einemblock zum Ende des Blocks springt, also aus dem Block heraus.

Probieren Sie es aus

(module  ;; import the browser console object, you'll need to pass this in from JavaScript  (import "console" "log" (func $log (param i32)))  (func    ;; create a local variable and initialize it to 0    (local $i i32)    (loop $my_loop      ;; add one to $i      local.get $i      i32.const 1      i32.add      local.set $i      ;; log the current value of $i      local.get $i      call $log      ;; if $i is less than 10 branch to loop      local.get $i      i32.const 10      i32.lt_s      br_if $my_loop    )  )  (start 1) ;; run the first function automatically)
const url = "{%wasm-url%}";await WebAssembly.instantiateStreaming(fetch(url), { console });

Syntax

wat
;; label the loop so that it can be branched to(loop $my_loop  ;; branch to the loop.  ;; most of the time you'll want to put this in an if statement and only branch on condition,  ;; otherwise you have an infinite loop.  br $my_loop)
InstruktionBinärer Opcode
loop0x03

Help improve MDN

Learn how to contribute Diese Seite wurde automatisch aus dem Englischen übersetzt.

[8]ページ先頭

©2009-2025 Movatter.jp