Hash Fellow robcat2075 Posted October 23, 2023 Hash Fellow Share Posted October 23, 2023 Chapter 21 Break and Continue Break and Continue give you ways to bypass instructions in a loop When break is encountered the program skips to the end of the loop and regards the loops as finished Exercise: copy your Week 10 X-maker program code to a new project and modify it with break so that it only prints a maximum of 10 Xs Example output Making Xs! How many Xs do you want? 6 XXXXXX How many Xs do you want? 2 XX How many Xs do you want? 25 XXXXXXXXXX How many Xs do you want? 57 XXXXXXXXXX How many Xs do you want? 0 I'm done! When continue is encountered, execution skips to the end of the loop, but then returns to the start of the loop and continues iterating the loop as before. Exercise: Write a program that prints out a range of numbers and after each one prints "is not a multiple of 3"... unless the number IS a multiple of 3, for which it prints nothing after the number. Use continue to skip the that message. Hint: This program probably makes some use of the modulo operation (%). sample output: Multiple of Three? 1 is not a multiple of 3. 2 is not a multiple of 3. 3 4 is not a multiple of 3. 5 is not a multiple of 3. 6 7 is not a multiple of 3. 8 is not a multiple of 3. 9 10 is not a multiple of 3. 11 is not a multiple of 3. 12 13 is not a multiple of 3. 14 is not a multiple of 3. 15 16 is not a multiple of 3. 17 is not a multiple of 3. 18 19 is not a multiple of 3. @Roger @Shelton @Rodney Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.