bitcoin-sv / sol2scrypt

Solidity to sCrypt Transplier
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Loop: break/continue #149

Closed xhliu closed 2 years ago

xhliu commented 2 years ago

https://scryptdoc.readthedocs.io/en/latest/loop.html#break

freedomhero commented 2 years ago

sol

for (uint i = 0; i < 10; i++) {
  if (i == 3) {
    if (i == 3) {
    // Skip to next iteration with continue
      continue;
    }
    uint a = 3;
  }
  if (i == 5) {
    // Exit loop with break
    break;
}
}

scrypt

bool loop_break_flag = false;
loop(__$SCR_LOOP_COUNT__): i {
  if (!loop_break_flag) {
   bool loop_continue_flag = false;

   if (i == 3) {
     if (i == 3) {
        loop_continue_flag = true;     
     }
     if(!loop_continue_flag) {
       uint a = 3;
     }
   }

   if (!loop_continue_flag) {
     if (i == 5) {
       loop_break_flag = true;
     }
   }
  }
}
xhliu commented 2 years ago

Just fail when continue & return are both present, since they may interfere w/ each other.

freedomhero commented 2 years ago

break resolved in https://github.com/sCrypt-Inc/sol2scrypt/pull/159

xhliu commented 2 years ago

Bug image