Support Home


Knowledge Base


Documentation


Contact Support


Unofficial Forum

Infinite loop caused by overflow

Question: I am using a for loop, which loop through 0 to 255 but loop never ends, why?

Answer: How does a variable overflow handled in TIDE? As we mentioned in our language philosophy, because Taiko application is not PC based, we do not halt the execution and pop up an error. What we do is that we simply discard the most significant digit in hex, if it is more than the type of the variable can hold. For example:

    dim b as byte
    b = 255 + 5

What value of b will be? The value of 255 in decimal is equal to FF in hexadecimal. So dec(255)+dec(5) = hex(FF)+hex(5), which equal to hex(104). The byte type variable can only hold 2 digits of hex, so we discard the most significant digit, which is 1, and the result of hex(FF) + hex(5) = hex(4). Therefore b is equal to 4. The valid value of byte variable is from 0 to 255, if we give it a value that is above 255, the value of b will start over from 0, and without stopping execution, or generate any kind of exception. For this reason, user should be careful when they are using the “for loop”. For example:

    dim b as byte
    dim j as byte
    b = 0
    j = 256
    for b = 250 to 255
        j = j+1
    next b

In the code above, user might think the variable is working within the maximum value of the byte type variable, but it is not. Because “for loop” automatically increment the value of b every time “next b” statement is reached. In the last loop (b = 255), the “next b” statement will try to assign 256 to b, which will bring b back to 0, and past the for loop condition, causing the code above, loop infinitely. The exact same code in VB will generate an overflow exception at “next b” statement in the last loop.


© Tibbo Technology Inc. 2001-2009   Contact Us | Account