0
 pragma solidity >= 0.8.2 <0.9.0;

contract Types { 
// Declaring a dynamic array
uint[] data; 
uint8 j = 0;
 function loop() public returns(uint[] memory){
while(j < 5) {
j++;
data.push(j);
}
return data;
}
 }

 On Remix IDE getting the error. ParserError: Function, variable, 
 struct or modifier declaration expected.
 --> contracts/Types.sol:5:16:
    |
  5 | contract Types { 
    |                ^
3
  • 2
    I checked the code in Remix and it does compile and deploy successfully. Could use some linting, but it does work.
    – Ake
    Commented Sep 21, 2023 at 7:38
  • 1
    I had the same positive result, can't find any errors...
    – titan2gman
    Commented Sep 21, 2023 at 7:45
  • the code compiles well on remix Commented Sep 21, 2023 at 9:06

1 Answer 1

0
// SPDX-License-Identifier: GPL-3.0




pragma solidity >=0.8.2 <0.9.0;

contract Types { 
   
    uint[] data; 
    uint8 j = 0;

    function loop() public returns (uint[] memory) {
        while (j < 5) {
            j++;
            data.push(j);
        }
        return data;
    }
}

as far as i can see, you just forget the license identifier to the top

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.