Note that there are some explanatory texts on larger screens.

plurals
  1. POC# how do I this simple else to loop until true?
    text
    copied!<p>I'm making a hangman game, this part of the code goes behind the button new game. Everytime the user selects new game I want the game to load a new word for users to guess. My problem is I need to put my code in to a loop. For example if non of the if/else statements are not true, select another random number until a statement is true...</p> <p>I hope that make sense =) Here's my code so far.</p> <pre><code>namespace HangMan { public partial class Form1 : Form { int RW; string previous; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { foreach (TextBox textBox in addTextBox()) { textBox.Visible = false; textBox.Text = ""; } } private static void LoadImages() { Image newImageIntro = Image.FromFile("HangmanIntro.jpg"); Image newImage1 = Image.FromFile("1.jpg"); Image newImage2 = Image.FromFile("2.jpg"); Image newImage3 = Image.FromFile("3.jpg"); Image newImage4 = Image.FromFile("4.jpg"); Image newImage5 = Image.FromFile("5.jpg"); Image newImage6 = Image.FromFile("6.jpg"); Image newImage7 = Image.FromFile("7.jpg"); Image newImage8 = Image.FromFile("8.jpg"); Image newImage9 = Image.FromFile("9.jpg"); } private void txtEnText_TextChanged(object sender, EventArgs e) { } private void txtEnText_Enter(object sender, EventArgs e) { } public List&lt;TextBox&gt; addTextBox() { List&lt;TextBox&gt; tBox = new List&lt;TextBox&gt;(); tBox.Add(textBox1); tBox.Add(textBox2); tBox.Add(textBox3); tBox.Add(textBox4); tBox.Add(textBox5); tBox.Add(textBox6); tBox.Add(textBox7); tBox.Add(textBox8); tBox.Add(textBox9); tBox.Add(textBox10); return tBox; } private void button1_Click(object sender, EventArgs e) { Random rW = new Random(); foreach (TextBox textBox in addTextBox()) { textBox.Visible = false; } RW = rW.Next(1, 4); if (RW == 1 &amp; previous != "1" ) //Cat { textBox1.Visible = true; textBox2.Visible = true; textBox3.Visible = true; previous = "1"; } else if (RW == 2 &amp; previous != "2" ) //Elephant { textBox1.Visible = true; textBox2.Visible = true; textBox3.Visible = true; textBox4.Visible = true; textBox5.Visible = true; textBox6.Visible = true; textBox7.Visible = true; textBox8.Visible = true; previous = "2"; } else if (RW == 3 &amp; previous != "3") //Giraffe { textBox1.Visible = true; textBox2.Visible = true; textBox3.Visible = true; textBox4.Visible = true; textBox5.Visible = true; textBox6.Visible = true; textBox7.Visible = true; previous = "3"; } else if (RW == 4 &amp; previous != "4") //Monkey { textBox1.Visible = true; textBox2.Visible = true; textBox3.Visible = true; textBox4.Visible = true; textBox5.Visible = true; textBox6.Visible = true; previous = "4"; } else { } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload