Hai vòng lặp while C++
C hỗ trợ lồng các vòng lặp trong C. Lồng các vòng lặp là tính năng trong C cho phép lặp các câu lệnh bên trong một vòng lặp khác. Hãy quan sát một ví dụ về vòng lặp lồng nhau trong C Show
Bất kỳ số lượng vòng lặp nào cũng có thể được xác định bên trong một vòng lặp khác, tôi. e. , không có giới hạn nào đối với việc xác định bất kỳ số lượng vòng lặp nào. Mức độ lồng nhau có thể được xác định tại n lần. Bạn có thể xác định bất kỳ loại vòng lặp nào bên trong một vòng lặp khác; Cú pháp của Vòng lặp lồng nhau Outer_loop và Inner_loop là các vòng lặp hợp lệ có thể là vòng lặp 'for', vòng lặp 'while' hoặc 'do-while' Một vòng lặp lồng nhau có nghĩa là một câu lệnh lặp bên trong một câu lệnh vòng lặp khác. Đó là lý do tại sao các vòng lặp lồng nhau còn được gọi là “vòng lặp bên trong vòng lặp“. Chúng ta có thể xác định bất kỳ số vòng lặp nào bên trong một vòng lặp khác 1. Lồng nhau cho vòng lặpVòng lặp for lồng nhau đề cập đến bất kỳ loại vòng lặp nào được xác định bên trong vòng lặp 'for'. Dưới đây là sơ đồ luồng tương đương cho các vòng lặp 'for' lồng nhau Vòng lặp lồng nhau trong C cú pháp for ( initialization; condition; increment ) { for ( initialization; condition; increment ) { // statement of inside loop } // statement of outer loop } Thí dụ. Chương trình bên dưới sử dụng vòng lặp for lồng nhau để in ma trận 3D 2x3x2 C
Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______6 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 119 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______11_______1 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______11_______3 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______11_______6 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Pattern Printing using Nested While loop 1 1 2 1 2 3 1 2 3 4 1 2 3 4 51 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Pattern Printing using Nested While loop 1 1 2 1 2 3 1 2 3 4 1 2 3 4 56 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);1 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);2_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);5 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);6 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);7_______32_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______6 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);7 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 Đầu ra Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 11 2. Vòng lặp lồng nhauVòng lặp while lồng nhau đề cập đến bất kỳ loại vòng lặp nào được xác định bên trong vòng lặp 'while'. Dưới đây là sơ đồ luồng tương đương cho các vòng lặp 'while' lồng nhau Vòng lặp lồng nhau trong C cú pháp while(condition) { while(condition) { // statement of inside loop } // statement of outer loop } Thí dụ. In mẫu bằng cách sử dụng các vòng lặp lồng nhau Cdo{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 3 3 5 77 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 * * * * * * * * * * * *2 * * * * * * * * * * * *3 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 * * * * * * * * * * * *7 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______271_______0 // C program to print elements of Three-Dimensional Array 1while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // C program to print elements of Three-Dimensional Array 5* * * * * * * * * * * *3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0____1_______2 // C program to print elements of Three-Dimensional Array 9while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______271_______0 // with the help of nested for loop 2while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // with the help of nested for loop 6// with the help of nested for loop 7while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2______272_______9 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0____1_______03 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______6 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);7 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 Đầu ra Pattern Printing using Nested While loop 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 3. Vòng lặp làm trong khi lồng nhauVòng lặp do-while lồng nhau đề cập đến bất kỳ loại vòng lặp nào được xác định bên trong vòng lặp do-while. Dưới đây là sơ đồ luồng tương đương cho các vòng lặp 'do-while' lồng nhau vòng lặp do while trong C cú pháp do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);
cú pháp do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition); Thí dụ. Chương trình dưới đây sử dụng vòng lặp for lồng nhau để in tất cả các thừa số nguyên tố của một số. CElement at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1116 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1117 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1118 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1120 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______23 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______271_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1126 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // with the help of nested for loop 6Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1131 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0____1_______33 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______38 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______40 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1145 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1146 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1147 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______1_______49 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______271_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1152 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // with the help of nested for loop 6Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1157 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2______1_______59 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______66 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1168 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______70 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1171 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // with the help of nested for loop 6Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1176 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1179 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1185 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1187 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______6 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);7 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 đầu ra. 3 3 5 7 Phá vỡ các vòng lặp lồng nhauBất cứ khi nào chúng ta sử dụng câu lệnh ngắt bên trong các vòng lặp lồng nhau, nó sẽ ngắt vòng lặp trong cùng và điều khiển chương trình nằm bên trong vòng lặp bên ngoài. Thí dụ. CElement at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1192 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1193 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }02 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }07 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }12 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______11_______14 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______1_______70 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }17 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);2_______11_______19 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }20 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }26 * * * * * * * * * * * *3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // C program to print elements of Three-Dimensional Array 5* * * * * * * * * * * *3 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______6 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);7 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 Đầu ra * * * * * * * * * * * * Trong chương trình trên, vòng lặp đầu tiên sẽ lặp từ 0 đến 5 nhưng ở đây nếu tôi bằng 3 thì nó sẽ bị ngắt và sẽ không in * như trong kết quả. Tiếp tục Bên trong các vòng lặp lồng nhauBất cứ khi nào chúng ta sử dụng câu lệnh continue bên trong các vòng lặp lồng nhau, nó chỉ bỏ qua bước lặp của vòng lặp trong cùng. Vòng lặp bên ngoài vẫn không bị ảnh hưởng Thí dụ Cwhile(condition) { while(condition) { // statement of inside loop } // statement of outer loop }41 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 1193 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 110 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 113 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 114 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 111 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______1_______2 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }02 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }07 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______11_______8 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 112 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }12 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______11_______63 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______1_______70 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }66 do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);2_______11_______68 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }20 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }2_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // with the help of nested for loop 6while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }76 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______41_______0 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }0_______32_______3 while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }9 // C program to print elements of Three-Dimensional Array 5* * * * * * * * * * * *3 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______0 Element at arr[0][0][0] = 0 Element at arr[0][0][1] = 6 Element at arr[0][1][0] = 1 Element at arr[0][1][1] = 7 Element at arr[0][2][0] = 2 Element at arr[0][2][1] = 8 Element at arr[1][0][0] = 3 Element at arr[1][0][1] = 9 Element at arr[1][1][0] = 4 Element at arr[1][1][1] = 10 Element at arr[1][2][0] = 5 Element at arr[1][2][1] = 115_______41_______6 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);7 do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);0 Trong chương trình trên, vòng lặp bên trong sẽ bị bỏ qua khi j bằng 2. Vòng lặp bên ngoài sẽ không bị ảnh hưởng Chúng ta có thể sử dụng 2 vòng lặp while trong C không?Chỉ một trong các vòng lặp while hoạt động .
Chúng ta có thể sử dụng 2 vòng lặp while không?Một vòng lặp while lồng nhau là một câu lệnh while bên trong một câu lệnh while khác . Trong một vòng lặp while lồng nhau, một lần lặp của vòng lặp bên ngoài được thực hiện đầu tiên, sau đó vòng lặp bên trong được thực hiện. Việc thực hiện vòng lặp bên trong tiếp tục cho đến khi điều kiện được mô tả trong vòng lặp bên trong được thỏa mãn.
Bạn có thể thêm vòng lặp while vào vòng lặp while không?Vòng lặp chứa vòng lặp bên trong vòng lặp được gọi là vòng lặp lồng nhau. Nó có thể chứa vòng lặp for bên trong vòng lặp for hoặc vòng lặp while bên trong vòng lặp while . Cũng có thể vòng lặp while có thể chứa vòng lặp for và ngược lại.
Chúng ta có thể sử dụng lồng nhau trong khi?Không bắt buộc phải lồng cùng loại vòng lặp . Chúng ta có thể đặt vòng lặp for bên trong vòng lặp while hoặc vòng lặp do-while bên trong vòng lặp for. |