英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论