Hello fellow programmers. I've started a new career path since my plant has shut down. C# programming and I am needing help. My class assignment was to make a console program that will display all possibilities of Military Time. I need the loop to stop the second time around at the 3 on the hours. I goes to 29 : 59 : 58 and below is what I have now. Code: static void Main(string[] args) { for(int h = 0; h <= 2; h++) { for(int H = 0; H <= 9; H++) { for(int m = 0; m <= 5; m++) { for(int M = 0; M <= 9; M++) { for(int s = 0; s <= 5; s++) { for(int S = 0; S <= 9; S++) { Console.WriteLine(h.ToString() + H.ToString() + " : " + m.ToString() + M.ToString() + " : " + s.ToString() + S.ToString()); } } } } } } string junk = Console.ReadLine(); } Can anyone help tell me what I have to do to get the loop to stop on the 23rd. hour. If I use a 3 in the H the time jumps from 3 hour to 10 hours instead of going through but I'm not sure how to stop the loop on just that one. Thank you for any help.
Maybe you want your result at stop point to be "23:00:00"? It's so easy to make a loop stop. To stop a loop you can use "break;" with some if condition. for an example without using "break", you can put the following line in your last For loop with S (the most inner loop and goes after the output command "Console.WriteLine"): if(h==2&&H==3) M=m=H=h=S=s=60; you can use another number greater than 60 that is mainly to make all conditions in all For loops to be not agreed. If you want to use "break", you have to put it in every For loop and use a proper if condition in each one. (like the form "if something break;" to exit the for loops one by one from inside to outside). Hope that help ! Thanks.