Removed 'if ... then ... else' and added 'while' for testing purpose