title: Loop with break or continue based on user input
body: <p>I loosely know how to use a loop. I've used simple ones and understand how it works. However, I have a situation where I think a loop would be useful, but I'm not quite certain how to get the desired result. I am self-taught in javascript and I've tried poking around some other posts, but I don't recall seeing anything that helped in my case. This may very well be one of my gaps in understanding.</p>
  
  <p>What I'd like this to do: This code is going to be taking the top card off a deck of cards for a TCG. Each card has a "type". I want the person to input a command into Discord like "!flipcard 10". I would like the bot to make a loop to flip cards off the top of the deck until 10 is reached OR a certain card type is flipped over. The card "types" I am working with are "action", "evo", "flip" and "hero". I only want the bot to react differently to the "Flip" card type. I have gotten working code to where I can do this if the user inputs !flipcard but does it one at a time. The maximum amount of cards that can ever be flipped is 34 cards or so, but this is less likely to happen than lower numbers. </p>
  
  <p>I just wrote the code up from what I think I need to do, but I get stuck with not knowing exactly where to go next. So it isn't exactly functioning code yet. I do get an "illegal break statement" error currently, so I can't progress much more. </p>
  
  <pre><code>for (i = 0; i &lt; damageToTake; i++) {
  cardRemoved = deckAarray.shift()
  
  
  //Bunch of stuff edited out for Embed mentioned below
  
      if (cardType == "Flip"){
         message.channel.send(flipEmbed)
         const filter = m =&gt; m.author.id === message.author.id
         author.send(`You revealed a Flip card! Do you wish to use it? Please reply with 'yes' or 'no'.`).then((newmsg) =&gt; {
         newmsg.channel.awaitMessages(filter, {
         max: 1,
          }).then((collected) =&gt; {
  
              reply = collected.first();
  
                if (reply.content == 'yes'){
                   console.log("Yes reply.")
                   break;
                } else if (reply.content == 'no'){
                   console.log("No reply")
                   } 
                  })
              })
              } else if (cardType != "Flip"){
                  message.channel.send(nonflipEmbed)
                  continue;
              }
          }
      })
      }
  
  </code></pre>
  
  <p>Like I mentioned, the code isn't working to a point I can try it and get a problem because I am getting an "illegal break statement" error. </p>
  
  <p>I think I am on the right track, but I'm uncertain how to make it work exactly how I'm hoping.</p>
  
  <p>So, to conclude...</p>
  
  <p>I would like this code to to the following: </p>
  
  <p>1)User inputs command and specifies how many cards to flip over.
  2)Loop should flip cards (displaying the correct embed based on card type)
  3)When a "flip" card type is revealed, I would like the code to pause, essentially, to ask the author whether or not they would like to use the Flip card that was revealed. If yes, stop the loop. If no, continue the loop from where it left off until the desired number are flipped OR if another Flip card type is revealed. </p>
  
  <p>Thanks for the help in advance!</p>