Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to break an infinite loop

How to break an infinite loop

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohamed Nehad
    wrote on last edited by
    #1

    If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.

    L F 2 Replies Last reply
    0
    • M Mohamed Nehad

      If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You have to include some code inside the loop to recognise the keystroke or some other event to break out of the loop. If you add a getch then that would pause the loop until the keystroke is delivered. To get round this you can put that code in a separate thread and set a flag for the loop to check. You could also use _kbhit[^], although it has limitations.

      1 Reply Last reply
      0
      • M Mohamed Nehad

        If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.

        F Offline
        F Offline
        Fuseteam
        wrote on last edited by
        #3

        if i'm not mistaken ctrl c(yes the copy shortcut) should break an infinite loop

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups