first translation from pseudocode