Remix IDE编译错误[E01002]: Aptos Move模块中的意外标记

huangapple go评论64阅读模式
英文:

Remix IDE compilation error[E01002]: unexpected token in Aptos Move module

问题

I'm new to Aptos Move.

I'm writing a smart contract but keep getting the E01002 error on my while loop. It was a for loop initially but changed to while because of error outputs.

        ...
        let release_times = vector::create();
        let total_num_drips = vector::length(&release_frequency);  

        let mut i = 0;
        while (i < total_num_drips) {
            let frequency = *vector::borrow(&release_frequency, i);
            let amount = *vector::borrow(&release_amount, i);
            let num_drips = total_amount / amount;
            let release_time = now + (i * frequency);

            let mut j = 0;
            while (j < num_drips) {
                vector::push(&mut release_times, release_time + (j * frequency));
                j += 1;
            };

            i += 1;
        }
        ...

the error output:

error[E01002]: unexpected token...
   
62          let mut i = 0;
                    ^
                    
                    Unexpected 'i'
                    Expected ';'

I've checked my code for unclosed code blocks, checked the move docs and rust docs, changed the control flow from 'for' to 'while' after checking through the docs and seeing no implementation using "for", same output nearly all the time.

英文:

I'm new to Aptos Move.

I'm writing a smart contract but keep getting the E01002 error on my while loop. It was a for loop initially but changed to while because of error outputs.

        ...
        let release_times = vector::create();
        let total_num_drips = vector::length(&release_frequency);  

        let mut i = 0;
        while (i < total_num_drips) {
            let frequency = *vector::borrow(&release_frequency, i);
            let amount = *vector::borrow(&release_amount, i);
            let num_drips = total_amount / amount;
            let release_time = now + (i * frequency);

            let mut j = 0;
            while (j < num_drips) {
                vector::push(&mut release_times, release_time + (j * frequency));
                j += 1;
            };

            i += 1;
        }
        ...

the error output:

error[E01002]: unexpected token...
   │
62 │         let mut i = 0;
   │                 ^
   │                 │
   │                 Unexpected 'i'
   │                 Expected ';'

I've checked my code for unclosed code blocks, checked the move docs and rust docs, changed the control flow from 'for' to 'while' after checking through the docs and seeing no implementation using "for", same output nearly all the time.

答案1

得分: 1

声明变量时无需指定可变性,在本地声明变量时,编译器会自动识别是否进行更改。

Move编译器也不支持递增运算符。

简单使用:let i = 0;

英文:

There's no need to specify mutability when declaring variables locally, the compiler knows automatically if changes are made.

Move's compiler also does not support the increment operator

Keep it simple with: let i = 0;

huangapple
  • 本文由 发表于 2023年5月29日 13:27:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354865.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定