That later version (which I sent to the u-boot list, did you see it) was for readability.  The code I proposed for size/speed was while (*ptr != '\0') { do { ptr++; } while (*ptr != '\0') ; ptr++; } There is an error in your code.  if the environment is empty, you will increment and write new variables.  These variables will not be able to be found, as the check for the beginning of the variables will always see the first null byte.