Skip to content
Sign upLog in
← Back to Community

how to do if repeat

Profile icon

so i made a question asking what is 5 + 10
Consol.Write("whats 5 + 10")
string userinput = (Console.ReadLine)

if userinput = "a"
Console.WriteLine("correct ")
else if
Console.WriteLine("sorry not correct pkease try again")
how do i make it to were if they get it wrong then it will let them try again?

Profile icon
Profile icon

use goto statement in else and in body of if statement in last use return 0;

Profile icon

You need to put your if/else code inside a while loop. The code below shows you how to use a boolean variable to control the loop's functioning.

using System; namespace Loops { class Program { static void Main(string[] args) { /* local variable definition */ int a = 0; bool keepGoing = true; /* while loop execution */ while (keepGoing) { Console.WriteLine("value of a: {0}", a); /* If a >= 10 then stop the looping by setting keepGoing to false */ if(a >= 10) { Console.WriteLine("The end!"); keepGoing = false; } a++; } Console.ReadLine(); } } }
Profile icon

Thank you very much


Profile icon

use a while loop

Profile icon

Thank you