Today, someone asked me if there is any goto in Java. When I read his questions, I knew that he was learning C. Well, I didn't really pay too much attention to this problem before, because I know that GOTO is a keyword in Java, but it seems that it has never been used, he asked me again, if you want to jump out of a few loops, how to operate?
I still have a way to solve this problem ......
- Public class testfor
- {
- Public static void main (string [] ARGs)
- {
- Testfor test = new testfor ();
- Test. testloopone ();
- System. Out. println ();
- System. Out. println ();
- Test. testlooptwo ();
- Int A [] = new int [10];
- A [0] = 2;
- A [1] = 4;
- A [2] = 22;
- A [3] = 3;
- A [4] = 9;
- A [5] = 12;
- A [6] = 11;
- A [7] = 6;
- A [8] = 5;
- A [9] = 0;
- Arrays. Sort ();
- }
- /**
- * Use flag Control
- */
- Public void testloopone ()
- {
- Hh:
- For (INT I = 0; I <10; I ++)
- {
- System. Out. println ("I value:" + I );
- For (int K = 0; k <10; k ++)
- {
- System. Out. println ("the value of K is:" + k );
- If (k = 6)
- Break HH;
- }
- }
- System. Out. println ("jump out of all loops ......");
- }
- /**
- * Use flag volume control
- */
- Public void testlooptwo ()
- {
- Int TMP = 0;
- For (INT I = 0; I <10; I ++)
- {
- System. Out. println ("I value:" + I );
- For (int K = 0; k <10; k ++)
- {
- System. Out. println ("the value of K is:" + k );
- TMP = K;
- If (k = 6)
- Break;
- }
- If (TMP = 6)
- Break;
- }
- System. Out. println ("jump out of all loops ......");
- }
- }
He gave me a warning from his problem. I have to learn things carefully in the future. Be careful ...... Remember!