Skip to content
Sign upLog in
← Back to Community

how to do if repeat

Profile icon
theoneto

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?

Voters
Profile icon
theoneto
Comments
hotnewtop
Profile icon
Moody875

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

Profile icon
[deleted]

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
theoneto

Thank you very much

@malvoliothegood

Profile icon
mwilki7

use a while loop

Profile icon
theoneto

Thank you

@mwilki7