rustmoveaptos

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.


Solution

  • 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;