Can we just write to the file in each case instead of write to a variable and then write to a file after the if statement?