Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to break out of multiple for loops at once in C++

1 Answer

0 votes
#include <iostream>
 
int main() 
{
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            for (int k = 0; k < 100; k++) {
                if (k == 10) {
                    goto ENDLOOPS;
                }
                std::cout << "i = " << i << " j = " << j << " k = " << k << "\n";
            }
        }
    }
 
ENDLOOPS:
 
    std::cout << "ENDLOOPS";
}
 
 
 
/*
run:
 
i = 0 j = 0 k = 0
i = 0 j = 0 k = 1
i = 0 j = 0 k = 2
i = 0 j = 0 k = 3
i = 0 j = 0 k = 4
i = 0 j = 0 k = 5
i = 0 j = 0 k = 6
i = 0 j = 0 k = 7
i = 0 j = 0 k = 8
i = 0 j = 0 k = 9
ENDLOOPS
 
*/

 



answered Apr 25, 2024 by avibootz

Related questions

1 answer 107 views
2 answers 153 views
1 answer 121 views
2 answers 178 views
178 views asked Sep 7, 2022 by avibootz
3 answers 215 views
3 answers 173 views
3 answers 185 views
...