C
C#15mo ago
krazycay

❔ how can i re use the readline after using it in a if statement

so basically im using readline and if it == "hello" for example, it'd writeline "hi!", then the program would exit. i'd like it to go back to readline after this. how can i do this?
// See https://aka.ms/new-console-template for more information
using ConsoleApp1;
using System.ComponentModel.Design;

namespace ConsoleApp1 // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
Console.Title = Settings.WinName;
Console.SetWindowSize(Settings.WinSize1, Settings.WinSize2);
Console.BufferHeight = Settings.BufHeight;
Console.BufferWidth = 97;
Console.WriteLine(Settings.Logo);
Console.Write(":> ");
if (Input.userResponse == "hi")
{
Console.WriteLine("no");
}
else if (Input.userResponse == "bad")
{
Console.WriteLine("trash");
Input.userResponse;
}
}
}
}
// See https://aka.ms/new-console-template for more information
using ConsoleApp1;
using System.ComponentModel.Design;

namespace ConsoleApp1 // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
Console.Title = Settings.WinName;
Console.SetWindowSize(Settings.WinSize1, Settings.WinSize2);
Console.BufferHeight = Settings.BufHeight;
Console.BufferWidth = 97;
Console.WriteLine(Settings.Logo);
Console.Write(":> ");
if (Input.userResponse == "hi")
{
Console.WriteLine("no");
}
else if (Input.userResponse == "bad")
{
Console.WriteLine("trash");
Input.userResponse;
}
}
}
}
36 Replies
krazycay
krazycay15mo ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// All of the settings can be changed from here

namespace ConsoleApp1
{
public class Input
{
public static string userResponse = Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// All of the settings can be changed from here

namespace ConsoleApp1
{
public class Input
{
public static string userResponse = Console.ReadLine();
}
}
no idea how i can do this
Shinigami
Shinigami15mo ago
You can keep the readline in a while loop?
krazycay
krazycay15mo ago
Alright lol how do i do that or wait shit well that just makes it write no constantly
Jimmacle
Jimmacle15mo ago
public class Input
{
public static string userResponse = Console.ReadLine();
}
public class Input
{
public static string userResponse = Console.ReadLine();
}
this is very much incorrect
Shinigami
Shinigami15mo ago
You can keep the readline in while loop and keep an if statement for exit, if user writes exit you'll exit out of the loop
Jimmacle
Jimmacle15mo ago
you should be using Console.ReadLine() directly and storing it in a local variable
krazycay
krazycay15mo ago
wdym? then how will i see what the readline is unless it's in a variable like that ah well
Jimmacle
Jimmacle15mo ago
local variable
krazycay
krazycay15mo ago
lmao wdym a local variable
Jimmacle
Jimmacle15mo ago
a variable declared in your method
krazycay
krazycay15mo ago
what i just started c# lmfao like 10 min ago dont know what im doing
Jimmacle
Jimmacle15mo ago
void MyMethod()
{
string userResponse = Console.ReadLine();
// do other stuff
}
void MyMethod()
{
string userResponse = Console.ReadLine();
// do other stuff
}
may i suggest $helloworld
krazycay
krazycay15mo ago
alr so
krazycay
krazycay15mo ago
that breaks the loop and not the if / else statements i want it to go back to the if userresponse == lol
Jimmacle
Jimmacle15mo ago
you don't need to break out of if/else statements just remove the breaks
krazycay
krazycay15mo ago
then it loops saying bad boy or trash or no and doesnt go back to user resonse lol
Jimmacle
Jimmacle15mo ago
then the code you're running isn't the code you're showing here every loop that should read a line, then print something out based on the input
krazycay
krazycay15mo ago
like look
krazycay
krazycay15mo ago
krazycay
krazycay15mo ago
ah fixed it
Jimmacle
Jimmacle15mo ago
you're also going to want to modify the variable used for your while loop condition inside the loop otherwise it'll loop forever
krazycay
krazycay15mo ago
thats the point :>
Jimmacle
Jimmacle15mo ago
to loop forever?
krazycay
krazycay15mo ago
yes
Jimmacle
Jimmacle15mo ago
if so you can use while (true)
krazycay
krazycay15mo ago
mm k yo @fixed(void* x = &Jimmacle) how can i make multiple while loops run at the same time
Jimmacle
Jimmacle15mo ago
what are you actually trying to do? the answer to that exact question is complicated for a beginner
krazycay
krazycay15mo ago
ive done what i want now i just want to figure out how to run another while true loop while the one i made before is running
Jimmacle
Jimmacle15mo ago
it's easier to help if i actually know the end goal
krazycay
krazycay15mo ago
Console.Title = Settings.WinName;
Console.SetWindowSize(Settings.WinSize1, Settings.WinSize2);
Console.BufferHeight = Settings.BufHeight;
Console.BufferWidth = 97;
Console.Title = Settings.WinName;
Console.SetWindowSize(Settings.WinSize1, Settings.WinSize2);
Console.BufferHeight = Settings.BufHeight;
Console.BufferWidth = 97;
constantly do that how do i do the goal i wanted to do lol just tell me that
Jimmacle
Jimmacle15mo ago
the short answer is multithreading but that doesn't seem like something you should do constantly in a loop i guess you could also use a timer
krazycay
krazycay15mo ago
it's gonna lock the terminal size basically what i want to do constantly resize it, anyway @fixed(void* x = &Jimmacle)
krazycay
krazycay15mo ago
krazycay
krazycay15mo ago
why doesnt this work lol figured it out
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.