Aug-18-2020, 03:27 PM
(This post was last modified: Aug-18-2020, 03:28 PM by deanhystad.)
Think about the logic. Currently you have
Harry has not finished his Homework = True
Harry has not eaten his Dinner = False
True and False == ?
Also, using else after a while statement is odd. You would use "else" if you wanted to differentiate exiting the loop because the while conditions were met from exiting the loop because of a "break". If you aren't using "break" you are just going to confuse anyone reading your code. Using else with a for loop is exactly the opposite. In a for loop the else code is only executed when the loop is terminated by a "break". So much for consistency. But nobody uses "else" with "while" and neither should you.
While Harry has not finished his Homework and Harry has not eaten his dinner No Xbox for Harry Harry can play XboxWhat happens if Harry ate dinner but didn't finish his homework?
Harry has not finished his Homework = True
Harry has not eaten his Dinner = False
True and False == ?
Also, using else after a while statement is odd. You would use "else" if you wanted to differentiate exiting the loop because the while conditions were met from exiting the loop because of a "break". If you aren't using "break" you are just going to confuse anyone reading your code. Using else with a for loop is exactly the opposite. In a for loop the else code is only executed when the loop is terminated by a "break". So much for consistency. But nobody uses "else" with "while" and neither should you.