However, you will need to immediately use the code as otherwise the time window for its usage will expire. This will require confirmation of identity by a onetime use code that Gmail will promptly send you on your listed Mobile phone number or another email.
But if you have no access due to forgetting the password or similar hacking problem then you will have to modify your new password by proving your identity. It is obviously more convenient to get access and then just change the account and save the new settings. To Gmail change password, you need not always have access to your account as long your security settings are updated. Learn how to manage password modification issues on Ipad and PC for Gmail