Guest User

Untitled

a guest
Apr 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. while loops allow you to repeat an if condition over and over for as long as that condition remains true, hence the name while!
  2.  
  3. To create a while loop, simply follow the same steps like an if condition, but replace the if with a while to look something like this:
  4.  
  5. while(isRaining){
  6. System.out.println("It's still raining outside!");
  7. isRaining = checkWeather();
  8. }
  9. System.out.println("Now it's not raining anymore");
  10. This code block above will continue to print the message "It's still raining outside!" for as long as the boolean isRaining is true, once the function checkWeather() returns false isRaining will no longer be true, so the while loop would end and the message "Now it's not raining anymore" will be displayed.
  11.  
  12. Unlike if blocks however, while loops don't have else blocks, they are simply like a repeated if block that would only end when the condition becomes false.
Add Comment
Please, Sign In to add comment