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,880 questions

51,806 answers

573 users

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

1 Answer

0 votes
#include <stdio.h>

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;
                }
                printf("i = %d j = %d k = %d\n", i, j, k);
            }
        }
    }

ENDLOOPS:

    puts("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 24, 2024 by avibootz
edited Apr 25, 2024 by avibootz

Related questions

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